我们可以在Python程序中使用TOR吗?

发布于 2025-01-24 02:40:31 字数 1023 浏览 3 评论 0原文

我尝试使用或更改IP地址,并在所有人访问的公共数据上进行网络刮擦,但找不到解决方案。我正在尝试进行旋转的IP地址。我在Windows 10和Anaconda IDE上。 例如,我在下面执行此代码:

import requests

domain = "https://www.undernews.fr"
#define your proxies
#the socks5h method allows the socks server to translate the #hostname. So make sure that you add 'socks5h'.
proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}
a = requests.get(domain.strip(), proxies=proxies).text
print(a)

以及我的内核返回:


  File "C:\Users\FirstName\anaconda3\lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)

ConnectionError: SOCKSHTTPSConnectionPool(host='www.undernews.fr', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x000001CF0D4EA3A0>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée'))

I try to use or change IP address and do web scraping on public data accessible by all but I can't find a solution. I am trying to do a rotating ip address. I'm on Windows 10 and the Anaconda IDE.
For example, i execute this code below:

import requests

domain = "https://www.undernews.fr"
#define your proxies
#the socks5h method allows the socks server to translate the #hostname. So make sure that you add 'socks5h'.
proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}
a = requests.get(domain.strip(), proxies=proxies).text
print(a)

And my kernel return:


  File "C:\Users\FirstName\anaconda3\lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)

ConnectionError: SOCKSHTTPSConnectionPool(host='www.undernews.fr', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x000001CF0D4EA3A0>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée'))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意 2025-01-31 02:40:31

看来这些代理已经被阻止:

错误的部分错误:
“无法建立连接,因为目标计算机明确拒绝了它

。获取“免费”代理的列表。或至少尝试使用其他代理IP

It looks like those proxies have been blocked:

Translated part of your error:
"No connection could be established because the target computer expressly refused it"

Maybe try looking into using proxyscrape to get a list of "free" proxies. Or at least try with a different proxy IP

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文