要求是在一定数量的呼叫后匿名报废或更改 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 模块问题的帮助将不胜感激。