当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 用到的库
import requests
# 写入获取到的ip地址到proxy
proxy = {
'https' : '221.178.232.130:8080'
}
# 用百度检测ip代理是否成功
url = 'https://www.baidu.com/s?'
# 请求网页传的参数
params={
'wd' : 'ip地址'
}
# 请求头
headers = {
'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
# 发送get请求
response = requests.get(url=url,headers=headers,params=params,proxies=proxy)
# 获取返回页面保存到本地,便于查看
with open( 'ip.html' , 'w' ,encoding= 'utf-8' ) as f:
f.write(response.text)
|
打开存入的“ip.html”查看内容如下;

以上就是python爬虫如何设置代理ip的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中的排序操作和heapq模块的介绍(代码示例)
Python爬虫学习图文实例
Python之搭建scrapy虚拟环境(windows版)
Python axis是什么意思
Python中绝对值怎么表示
Python保存数组怎么操作
Python的单线程多任务的实现
怎么看Python安装了哪些库
Python中预处理以及热图的简单介绍
Python格式化输出%s和%d
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python爬虫如何设置代理ip