1 2 3 4 5 6 7 8 9 10 11
| import requests url="https://www.sogou.com/web?query=周杰伦"
headers={ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55" } #以字典的形式设置请求头,处理反爬 resp=requests.get(url,headers=headers) print(resp) #结果:Response [200] print(resp.text) #拿到页面源代码 resp.close() #关掉resp
|