0

我正在编写一个 selenium 脚本来访问安装服务人员的网站列表。我想要做的是,如果 selenium 访问一个网站,它应该等待 service worker 安装好,然后再转到下一个网站或退出 selenium 驱动程序。目前,我的代码如下所示。

        for url in tqdm(list_urls):
            driver = get_driver() # gets driver from helper function.
            print(f'Doing {url} {list_urls.index(url)+1}/{len(list_urls)}')
            try:
                driver.get(url)
                sleep(10) # probably not the best way to do it.
            
            except: # if there is a selenium timeout exception.
                print(f'{url} did not work ... will try again.')
                repeat_list.append(url)
        
            driver.quit()

我有一个sleep(10)我认为不是最好的方法。有可能在 1 秒内安装了 service worker(它闲置了 9 秒什么都不做),或者在 10 秒内没有安装 service worker。我将为数千个网站列表执行此操作。我知道 selenium 中有隐式、显式和流畅的等待语句,但我没有找到任何对我有用的东西。

4

0 回答 0