我们自己去360搜索Python发现url为:https://www.so.com/s?ie=utf-8&fr=none&src=360sou_newhome&q=Python
requests.get(url, params=kv)
params 用于追加参数到url中
代码
import requests
def getHTMLText(url):
try:
keyword = {'ie': 'utf-8', 'fr': 'none', 'src': '360sou_newhome', 'q': 'Python'}
r = requests.get(url, params=keyword, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except Exception as err:
return str(err)
if __name__ == '__main__':
url = 'http://www.so.com/s'
print(getHTMLText(url))
结果
如果我们返回r.url 结果为: ![](https://img2020.cnblogs.com/blog/1898562/202003/1898562-20200308212607673-80460529.png)