使用Selenium进行Web Scraping,带有两个下拉菜单

时间:2016-04-05 20:06:41

标签: python selenium drop-down-menu

我正在尝试制作一个循环浏览两个下拉菜单的网络抓取工具,但我似乎找不到使用selenium的第一个下拉框。我要在下拉框中循环显示所有名称和年份,并将所有页面和值的表导出到csv。该网页为:http://surge.srcc.lsu.edu/s1.html

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://surge.srcc.lsu.edu/s1.html")

element = driver.find_element_by_xpath('//select[@id="storm_name"]')
all_options = element.find_elements_by_tag_name("option")

我的错误是:

NoSuchElementException: Unable to locate element:
{"method":"xpath","selector":"//select[@id=\"storm_name\"]"}

1 个答案:

答案 0 :(得分:0)

因为@HumphreyTriscuit我会将此作为答案发布。如果是的话,请花时间将其标记为答案。

所以你去了:

这是因为您没有加载正确的网页来查找您的元素。 Your webpage包含指向actual content的iFrame,但我认为Selenium无法预加载iFrame。获取此页面,您的代码应该可以正常运行。

此处还有一点奖励:如果您不确定xPath,请考虑使用xPath Checker for Firefox