Following the guide Scraping Websites with Python, Selenium, and Tor I don’t know how could I wait only until the tor browser is connected instead of waiting a fixed amount of time. Something like what there is in the comment below, which isn’t working right now. The torStatus is just an example with doesn’t really exist. I’m looking for an actual way to tell when it is connected.

def connect_tor() -> None:
    driver.find_element(By.XPATH, '//*[@id="connectButton"]').click()
    #while driver.find_element(By.XPATH, '//*[@id="torStatus"]').get_attribute("value") != "connected":
        #time.sleep(1)
    time.sleep(20)
@OptimusPrime
creator
link
fedilink
22M

It was easier than I expected:

while driver.find_element(By.XPATH, '//*[@id="connectLongContent"]').is_displayed():
        time.sleep(1)

There is also the tor-browser-selenium library to consider.

Ask specific questions about how to code something in python

Python docs (tutorial)
Intro to programming - University of Helsinki

General python discussion on lemmy.ml

Create Post From:
lemmy.ml

  • 0 users online
  • 1 user / day
  • 1 user / week
  • 5 users / month
  • 7 users / 6 months
  • 22 subscribers
  • 13 Posts
  • 22 Comments
  • Modlog