硒在寻找元素时要等待很长时间



我正在开发一个软件,用于在网站的源代码中查找电子邮件地址。但有时网站的来源很长,所以搜索时间很长。我如何设置一个特定的时间,并让它在这个时间到期后切换到其他网站的网址?

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)

结果=[]start_time=time.time((对于my_list中的查询:results.append(搜索(查询,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)
if time.time() - start_time > 10:
# if 10 seconds pass do something
start_time = time.time()
time.sleep(3)
driver.close()
import time
start_time = time.time()
# your code
while True:
if time.time() - start_time > 2:
# if 2 seconds pass do something
start_time = time.time()
print("2 seconds passed")

您可以使用python时间模块等待一段时间,如下所示:

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

相关内容

  • 没有找到相关文章

最新更新