请求代理不工作 [英] Requests Proxy not Working

查看:23
本文介绍了请求代理不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个用于测试的抓取工具,我想使用不同的 IP 访问该站点,我发现了很多有关使用代理的信息并尝试了多次,但是当我访问一个显示所使用 IP 的站点时请求,它显示了我的计算机的 IP.

I am currently writing a scraper for testing want to access the site with a different IP, I have found a lot of information about using a proxy and tried this several times, however when I access a site that shows the IP used in the request, it shows the IP of my computer.

我使用的是在网上找到的免费代理.

I am using a free Proxy I found online.

这是我的代码:

import requests
proxy = {'SOCKS5': '24.145.195.60:27595'}
response = requests.get('http://www.whatsmyip.de/', proxies=proxy)
print response

非常感谢任何帮助!

推荐答案

您需要为 HTTP 和/或 HTTPS 协议定义代理.我不确定 requests 是否适用于 SOCKS 协议

You need to define a proxy for the HTTP and or a HTTPS protocol. I'm not sure if requests works with SOCKS protocol yet

这对我有用.

import requests
import bs4

proxy = {"http": "115.227.195.213"}
response = requests.get('http://www.whatsmyip.de/', proxies=proxy)
soup = bs4.BeautifulSoup(response.text)

print soup.h3.text

注意:它使用bs4 模块来打印ip,我使用了代理服务器与 HTTP 兼容

Note: It uses the bs4 module to print the ip and I used a proxy server that is HTTP compatible

这篇关于请求代理不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆