Home > database >  Selenium wait a lot while searching for element
Selenium wait a lot while searching for element

Time:12-13

I am working on a software to find email addresses in source codes of websites. But sometimes the sources of the websites are very long, so it searches for a long time. How can I set a certain time for this and have it switch to the other website url after this time expires?

    for query in my_list:
        results.append(search(query, tld="com", num=3, stop=3, pause=2))

    for result in results:
        url = list(result)
        print(*url,sep='\n')
        for site in url:
            driver = webdriver.Chrome()
            driver.get(site)
            doc = driver.page_source
            emails = re.findall(r'[\w\.-] @[\w\.-] ', doc)
            for email in emails:
                print(email)

CodePudding user response:

You can wait a bit providing time using python time module as follows:

import time

for site in url:
    driver = webdriver.Chrome()
    driver.get(site)
    time.sleep(8)

       

CodePudding user response:

import time
start_time = time.time()

# your code


if time.time() - start_time > 10:
    # if 10 seconds pass do something
    start_time = time.time()
  • Related