本文主要是介绍python爬虫,随机更换代理ip,User-Agent, Referer,方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import requests
import randomurl = "https://www.baidu.com" #访问页面
ip_list = [ #ip存放地址'223.159.28.152:8080','113.200.105.45:8080','110.229.233.76:8080','125.79.15.140:8888'
]def change_ip_info():#不同类型的操作系统以及浏览器的标识user_agent_list=['Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',]#请求是从哪个链接而来的referer_list=['https://www.sogou.com/','https://www.so.com/',# 'https://www.baidu.com/',]#随机抽取user_agent和referer设置Headers识别header = {'User-Agent':random.choice(user_agent_list),
这篇关于python爬虫,随机更换代理ip,User-Agent, Referer,方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!