当前第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 编程开发 实用经验和技巧大放送
Python set是什么类型
Python爬虫是什么?为什么把Python叫做爬虫?
Python整数怎么表示
通过游戏闯关来测试自己的Python掌握能力
Python文本编辑器是什么
Python如何提高运行速度
编写专属的Python模块
Python tuple怎么用
对Python的链表数据结构讲解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python爬虫如何设置代理ip