I am trying to use tor browser, and get a new IP address each URL I visit in python. I am able to open an instance of selenium running the tor browser, but how can I request a
To use Python to request a new IP for every request, you need to open a connection to the ControlPort and issue a NEWNYM signal.
You can use Stem to simplify the connection and commands:
from stem.control import Controller
from stem import Signal
if __name__ == '__main__':
with Controller.from_port(port = 9051) as controller:
controller.authenticate('password') # provide the password here if you set one
controller.signal(Signal.NEWNYM) # switch to clean circuits
Keep in mind Tor may rate limit NEWNYM
requests so you may need to wait a short while (default 10 seconds) before issuing that command. Also, due to the limited number of exit nodes, your circuits might get the same exit node depending on how many requests you are issuing.
You need to issue this command every time you want to get a new IP (switch circuits).