Python 3.x 如何使用Selenium和Python循环浏览URL列表
大家好,我想在selenium中每循环一次url,当chrome驱动程序弹出时,必须更改列表中的url这是我的想法代码:Python 3.x 如何使用Selenium和Python循环浏览URL列表,python-3.x,selenium,loops,selenium-webdriver,webdriver,Python 3.x,Selenium,Loops,Selenium Webdriver,Webdriver,大家好,我想在selenium中每循环一次url,当chrome驱动程序弹出时,必须更改列表中的url这是我的想法代码: from selenium import webdriver List = ['http://facebook.com','http://youtube.com','http://google.com'] while True: driver = webdriver.Chrome() driver.get(List) driver.quit(
from selenium import webdriver
List = ['http://facebook.com','http://youtube.com','http://google.com']
while True:
driver = webdriver.Chrome()
driver.get(List)
driver.quit()
尝试itertools.cycle()在列表中无限循环
from selenium import webdriver
import itertools
List = ['http://facebook.com','http://youtube.com','http://google.com']
for url in itertools.cycle(List):
driver = webdriver.Chrome()
driver.get(url)
driver.quit()
使用range()来限制无限循环。要使用以下解决方案在URL列表中循环:
- 代码块:
from selenium import webdriver import time url_list = ['http://facebook.com','http://youtube.com','http://google.com'] for url in url_list: driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe') driver.get(url) time.sleep(3) print(driver.title) driver.quit()
- 控制台输出:
Facebook – log in or sign up YouTube Google