Connect to .onion websites on tor using python?

后端 未结 1 844
说谎
说谎 2020-12-20 18:37

Here is the code that i have till now

import socks
import socket
import requests
import json

socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5, addr=         


        
相关标签:
1条回答
  • 2020-12-20 18:56

    Try to avoid the monkey patching if possible. If you're using modern version of requests, then you should have this functionality already.

    import requests
    import json
    
    proxies = {
        'http': 'socks5h://127.0.0.1:9050',
        'https': 'socks5h://127.0.0.1:9050'
    }
    
    data = requests.get("http://altaddresswcxlld.onion",proxies=proxies).text
    
    print(data)
    

    It's important to specify the proxies using the socks5h:// scheme so that DNS resolution is handled over SOCKS so Tor can resolve the .onion address properly.

    0 讨论(0)
提交回复
热议问题