Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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