简体   繁体   English

带有 Tor 的 Python requests-html

[英]Python requests-html with Tor

The requirement is to scrap anonymously or change ip after certain number of calls.要求是在一定数量的呼叫后匿名报废或更改ip。 I use the https://github.com/kennethreitz/requests-html module to parse the HTML, but i get the below error,我使用https://github.com/kennethreitz/requests-html模块来解析 HTML,但出现以下错误,

socks.SOCKS5Error: 0x01: General SOCKS server failure

Code代码

import socks
import socket
import requests_html

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, addr='127.0.0.1', port=int('9150'))
socket.socket = socks.socksocket

session = requests_html.HTMLSession()
r = session.get('http://icanhazip.com')
r.html.render(sleep=5)
print(r.html.text)

But it works perfectly fine with requests module,但它与请求模块完美配合,

import socks
import socket
import requests

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, addr='127.0.0.1', port=int('9150'))
socket.socket = socks.socksocket

print(requests.get("http://icanhazip.com").text)

Any help to solve the issue with requests-html module would be highly appreciated.任何解决 requests-html 模块问题的帮助将不胜感激。

Try:尝试:

session = requests_html.HTMLSession(browser_args=["--no-sandbox","--proxy-server=127.0.0.1:9150"])

Depends on how your proxy is set up to use tor but this worked for me!取决于您的代理是如何设置为使用 tor 的,但这对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM