我尝试使用Python和Selenium来抓取这个网站,它要求您从下拉框中选择一个日期,然后单击search来查看计划应用程序。在
网址:https://services.wiltshire.gov.uk/PlanningGIS/LLPG/WeeklyList。在
我有代码来选择下拉框的第一个索引并按搜索。我该如何为下拉框中的所有日期选项打开多个窗口,还是逐个浏览这些窗口,以便我可以快速浏览?在
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome('/Users/weaabduljamac/Downloads/chromedriver',
chrome_options=options)
url = 'https://services.wiltshire.gov.uk/PlanningGIS/LLPG/WeeklyList'
driver.get(url)
select = Select(driver.find_element_by_xpath('//*[@id="selWeek"]'))
select.select_by_index(1)
button = driver.find_element_by_id('csbtnSearch')
button.click()
app_numbers = driver.find_element_by_xpath('//*[@id="form1"]/table/tbody/tr[1]/td[1]/a').text
print(app_numbers)
下拉框HTML:
^{pr2}$
根据您的问题,您将无法为不同的下拉选项打开多个窗口,因为
<options>
标记不包含任何href
属性。它们将始终在同一个浏览器窗口中呈现新页面。在但是,要从下拉列表中选择日期,然后
click()
搜索查看计划应用程序,可以使用以下解决方案:代码块:
控制台输出:
琐事
要清除所有需要替换的链接:
有:
您可以在“搜索”按钮上执行
click + ctrl
,在新窗口中打开链接,丢弃数据,并返回到第一页以选择下一个选项我很确定这是不可能的,你必须循环使用这些选项并将数据存储在某处,然后从每个下拉列表中添加新数据。在
希望这有帮助。在
相关问题 更多 >
编程相关推荐