3

要求是在一定数量的呼叫后匿名报废或更改 IP。我使用https://github.com/kennethreitz/requests-html模块解析 HTML,但出现以下错误,

socks.SOCKS5Error: 0x01: General SOCKS server failure

代码

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)

但它与 requests 模块完美配合,

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)

任何解决 requests-html 模块问题的帮助将不胜感激。

4

1 回答 1

0

尝试:

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

取决于您的代理是如何设置为使用 tor 的,但这对我有用!

于 2020-12-21T21:50:41.840 回答