爬虫之添加代理(五)

验证代理是否可用

    try:
        telnetlib.Telnet('221.15.192.96', port='1080', timeout=3)
    except:
        print('ip无效!')
    else:
        print('ip有效!')

添加代理

添加proxy属性

import requests
from random import choice
proxies= [
    'http://196.52.58.239:80',
    'http://165.225.112.77:10605',
    'http://165.225.76.70:10605',
    'http://122.226.57.70:8888',
    'http://123.57.84.116:8118',
    'http://202.109.157.64:9000',
    'http://139.155.41.15:8118',
    'http://39.106.223.134:80',
    'http://47.115.63.52:8888'
]
proxy = choice(proxies)
session = requests.Session()
page_text = session.get(url=url, proxy=proxy, headers=headers)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值