Javascript (s:12648) 在DelayedCommand.prototype.execute/=谁显示了一些错误。我不明白为什么。@BoobaGump是的,我的错。你能试试更新的代码吗? from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get("http://www.hillsproducts.com/General.aspx/en-GB/PD/a-d-canine/original/can") index = 0 while True: select = Select(driver.find_element_by_id("productSpecifier_product")) # exit the loop if all the options were seen if index >= len(select.options): break select.select_by_index(index) print(driver.current_url) index += 1
每次加载新页面时,必须重新实例化Javascript (s:12648) 在DelayedCommand.prototype.execute/=谁显示了一些错误。我不明白为什么。@BoobaGump是的,我的错。你能试试更新的代码吗? from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get("http://www.hillsproducts.com/General.aspx/en-GB/PD/a-d-canine/original/can") index = 0 while True: select = Select(driver.find_element_by_id("productSpecifier_product")) # exit the loop if all the options were seen if index >= len(select.options): break select.select_by_index(index) print(driver.current_url) index += 1,javascript,python,selenium,selenium-webdriver,web-scraping,Javascript,Python,Selenium,Selenium Webdriver,Web Scraping,每次加载新页面时,必须重新实例化Select(): from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get("http://www.hillsproducts.com/General.aspx/en-GB/PD/a-d-canine/original/can") index = 0 while True:
Select()
:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get("http://www.hillsproducts.com/General.aspx/en-GB/PD/a-d-canine/original/can")
index = 0
while True:
select = Select(driver.find_element_by_id("productSpecifier_product"))
# exit the loop if all the options were seen
if index >= len(select.options):
break
select.select_by_index(index)
print(driver.current_url)
index += 1
谢谢你的快速回答!这是一项高效率的工作。但在我运行了你的代码后仍然显示错误。我用新的错误更新了问题。它只是
如果索引>=
谁显示了一些错误。我不明白为什么。@BoobaGump是的,我的错。你能试试更新的代码吗?
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get("http://www.hillsproducts.com/General.aspx/en-GB/PD/a-d-canine/original/can")
index = 0
while True:
select = Select(driver.find_element_by_id("productSpecifier_product"))
# exit the loop if all the options were seen
if index >= len(select.options):
break
select.select_by_index(index)
print(driver.current_url)
index += 1