带代理的python请求

时间:2019-07-15 14:30:40

标签: python proxy python-requests

我想将代理与python请求库一起使用

import requests

proxy_req = {'http':'177.53.57.154:48926'}

url = 'https://www.companyweb.be/en'
ua = UserAgent()
headers = {'User-Agent':ua.random}

r = requests.get(url = url, headers = headers,proxies=proxy_req)

soup = bs.BeautifulSoup(r.text, 'html.parser')

我收到响应,但是查询似乎忽略了代理(因为它太快了)

我试图通过此操作获取IP并检查它是否是代理IP地址:

r = requests.get(url = url, headers = headers,proxies=proxy_req, stream = True)
print(r.raw._fp.fp.raw._sock.getpeername())

但是我得到这个错误:

AttributeError: 'WrappedSocket' object has no attribute 'getpeername'

怎么了?

0 个答案:

没有答案
相关问题