import requests
def main(url):
try:
params = {
'kv':'Python'} # 输入要查询的关键字,字典形式,注意字典中的键值
resp = requests.get(url, params = params) #params传入
resp.raise_for_status()
print(resp.request.url)
resp.encoding = resp.apparent_encoding # encoding查请求头的编码,apparent_encoding查看内容的编码
print(len(resp.text))
return resp.text
except:
return '爬取失败'
if __name__ == '__main__':
url = 'http://www.baidu.com/s'
print(main(url))