import requests if __name__ == "__main__": url = "http://sogou.com/web" # 处理url参数:封装到字典中 kw = input("输入一个参数") params = { "query": kw } #user-agent伪装 headers = { "user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.0.12022 SLBChan/30", "cookie":"IPLOC=CN5200; SUID=F4DABD75492CA20A0000000063A801DC; SUV=1671954909692186; ABTEST=7|1671954910|v17; SNUID=785630F88D887C2EDB78C2448D8D3C14; sst0=104; ld=lZllllllll20$l4OlllllpnoxRylllllNbTzdlllllUlllllpylll5@@@@@@@@@@", } #对指定的url发起请求 resp = requests.get(url, params=params,headers=headers) print(resp.status_code) page_text = resp.text file_name= kw+".html" with open(file_name,"w",encoding="utf-8") as fp: fp.write(page_text) print("保存成功")
requests网页采集器
最新推荐文章于 2024-09-06 23:41:09 发布