Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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
Python 3.x 如何使用Beautifulsoup和Selenium一个接一个地选择下拉菜单动态生成数据?_Python 3.x_Selenium_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 3.x 如何使用Beautifulsoup和Selenium一个接一个地选择下拉菜单动态生成数据?

Python 3.x 如何使用Beautifulsoup和Selenium一个接一个地选择下拉菜单动态生成数据?,python-3.x,selenium,web-scraping,beautifulsoup,Python 3.x,Selenium,Web Scraping,Beautifulsoup,我想从以下网站获取数据: 在这里,数据是在同一页面上动态生成的,URL没有任何变化。 每次从第一个下拉菜单中选择选项时,只有第二个下拉菜单变为活动状态,并允许您从第二个下拉菜单中选择选项,依此类推第三和第四个下拉菜单 选择所有下拉菜单后,您必须单击搜索按钮,然后在同一页面上只生成数据 我需要一次完成所有可能选择的数据。下面是我尝试过的代码,但它无法按预期工作。我使用python和工具作为beautifulsoup&selenium。帮我做这个 Mike67,我已经使用了您的建议和改进的代码,但

我想从以下网站获取数据:

在这里,数据是在同一页面上动态生成的,URL没有任何变化。 每次从第一个下拉菜单中选择选项时,只有第二个下拉菜单变为活动状态,并允许您从第二个下拉菜单中选择选项,依此类推第三和第四个下拉菜单

选择所有下拉菜单后,您必须单击搜索按钮,然后在同一页面上只生成数据

我需要一次完成所有可能选择的数据。下面是我尝试过的代码,但它无法按预期工作。我使用python和工具作为beautifulsoup&selenium。帮我做这个

Mike67,我已经使用了您的建议和改进的代码,但仍然无法在选项中迭代并将代码保存到dataframe。帮我做这个!! 代码:


如果在每次下拉列表更改之间调用
time.sleep
,则页面将工作:

driver.get("http://b2b.godrejinterio.com/GodrejInterio/dealer.aspx?id=29&menuid=2458&business=2")

time.sleep(2)
s1 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlRange"))
s1.select_by_value("Institutional Furniture")
print(s1.options[0].text)

time.sleep(2)
s2 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlSubRange"))
s2.select_by_value("Desking")

time.sleep(2)
s3 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlState"))
s3.select_by_value("Delhi")
print(s3.options[0].text)

driver.find_element_by_id("ucInterioDealerLocatorNewRight_imgBtnSearch").click()

你到底被困在哪里?哪一行?看到错误了吗?请使用driver.implicitly_wait()而不是sleep。
driver.get("http://b2b.godrejinterio.com/GodrejInterio/dealer.aspx?id=29&menuid=2458&business=2")

time.sleep(2)
s1 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlRange"))
s1.select_by_value("Institutional Furniture")
print(s1.options[0].text)

time.sleep(2)
s2 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlSubRange"))
s2.select_by_value("Desking")

time.sleep(2)
s3 = Select(driver.find_element_by_id("ucInterioDealerLocatorNewRight_ddlState"))
s3.select_by_value("Delhi")
print(s3.options[0].text)

driver.find_element_by_id("ucInterioDealerLocatorNewRight_imgBtnSearch").click()