python,requests中获取网页源代码,与右键查看的源代码不一致,求解!!! 下面是代码,不知有何错误?
importrequestsurl='https://www.baidu.com/s?wd=周杰伦'#查询信息headers={"User-Agent":"Mozilla...
import requests
url = 'https://www.baidu.com/s?wd=周杰伦' # 查询信息
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36"
" (KHTML, like Gecko) Chrome/89.0.4389.90 Mobile Safari/537.36 Edg/89.0.774.54"
}
res = requests.get(url, headers=headers) # 使用get方法获得
# res.encoding = 'utf-8'
# print(res)
print(res.text) # 打印网页源代码 展开
url = 'https://www.baidu.com/s?wd=周杰伦' # 查询信息
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36"
" (KHTML, like Gecko) Chrome/89.0.4389.90 Mobile Safari/537.36 Edg/89.0.774.54"
}
res = requests.get(url, headers=headers) # 使用get方法获得
# res.encoding = 'utf-8'
# print(res)
print(res.text) # 打印网页源代码 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询