当前位置:   article > 正文

requests使用ip代理时单ip和多ip设置方式,智联招聘小爬虫封装_python requests请求 分ip

python requests请求 分ip

reqeusts库,在使用ip代理时,单ip代理和多ip代理的写法不同
(目前测试通过,如有错误,请评论指正)

  • 单ip代理模式
    省去headers等

    import requests
    proxy = {
        'HTTPS': '162.105.30.101:8080'
    }
    url = '爬取链接地址'
    response = requests.get(url,proxies=proxy)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 多ip代理模式

import requests
#导入random,对ip池随机筛选
import random
proxy = [
    {
        'http': 'http://61.135.217.7:80',
        'https': 'http://61.135.217.7:80',
    },
{
        'http': 'http://118.114.77.47:8080',
        'https': 'http://118.114.77.47:8080',
    },
{
        'http': 'http://112.114.31.177:808',
        'https': 'http://112.114.31.177:808',
    },
{
        'http': 'http://183.159.92.117:18118',
        'https': 'http://183.159.92.117:18118',
    },
{
        'http': 'http://110.73.10.186:8123',
        'https': 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/480359
推荐阅读
相关标签
  

闽ICP备14008679号