0
嗨,我一直在試圖改變我的IP後,刮一個網站的一些要求,但是當我運行這個代碼,這是我在一些博客上發現的代碼,發生任何事情,我的意思是我的IP是兩個產出也是如此。任何人都知道我做錯了什麼?爲什麼不能更改我的IP? Tor&Python
from stem import Signal
from stem.control import Controller
import requests
def set_new_ip():
"""Change IP using TOR"""
with Controller.from_port(port=9051) as controller:
controller.authenticate(password='my_password')
controller.signal(Signal.NEWNYM)
local_proxy = '127.0.0.1:8118'
http_proxy = {'http://': local_proxy,
'https://': local_proxy}
current_ip = requests.get(url='http://icanhazip.com/',
proxies=http_proxy,
verify=False)
print(current_ip.text)
set_new_ip()
current_ip = requests.get(url='http://icanhazip.com/',
proxies=http_proxy,
verify=False)
print(current_ip.text)