1 year ago

#306968

test-img

mkde

How to change IP while using Selenium with a Tor instance

I was trying to use Selenium with a Tor instance but I got caught in the Cloudflare page. So I wanted to change the IP address until it doesn't require Cloudflare check. I used the function below to renew the Tor instance but it didn't work. I imported Stem and other utilities.

from stem import Signal
from stem.control import Controller
def renew_connection():
       with Controller.from_port(port = 9050) as controller:
       controller.authenticate(password="My authentication code")
       controller.signal(Signal.NEWNYM) 

Here you can see my preferences

profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()

When I use the renew_connection() function it gives a connection error. So what do you suggest to renew the IP address.

python

selenium

tor

stem

0 Answers

Your Answer

Accepted video resources