python爬虫如何设置代理ip


当前第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”查看内容如下;

91f788d9d8a376f6d3ccd24a1c01f56.png

以上就是python爬虫如何设置代理ip的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python中的排序操作和heapq模块的介绍(代码示例)

Python爬虫学习图文实例

Python之搭建scrapy虚拟环境(windows版)

Python axis是什么意思

Python中绝对值怎么表示

Python保存数组怎么操作

Python的单线程多任务的实现

怎么看Python安装了哪些库

Python中预处理以及热图的简单介绍

Python格式化输出%s和%d

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...