簡體   English   中英

帶有 Tor 的 Python requests-html

[英]Python requests-html with Tor

要求是在一定數量的呼叫后匿名報廢或更改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)

但它與請求模塊完美配合,

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 模塊問題的幫助將不勝感激。

嘗試:

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

取決於您的代理是如何設置為使用 tor 的,但這對我有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM