我正在尝试抓取显示案例列表的页面,每个案例都是提交表单的回发链接,响应是带有详细信息的 JavaScript 弹出窗口的同一页面。我可以要求任何人,但我无法让 switch_to.window 或 switch_to.frame 工作。这种类型的链接有什么技巧吗?
可运行的代码片段
import undetected_chromedriver.v2 as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import sys
'''
Requires chrome
pip install selenium
pip install undetected_chromedriver
'''
driver = uc.Chrome()
txtUsingTestDates = 'Using test dates'
print(txtUsingTestDates.center(20, "="))
dateStart = "08/02/2021"
dateEnd = "08/02/2021"
with driver:
driver.get('https://publicindex.sccourts.org/abbeville/publicindex/')
try:
formAcceptTerms = driver.find_element(By.XPATH, "//*[@id='form1']")
except:
print("Didn't find form")
try:
driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_ButtonAccept']").click()
print(">>>Accepting terms")
except:
print("Didn't find button")
### Search form
#Select court
selectorCourts = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListCourtType']"))
selectorCourts.select_by_visible_text('Circuit Court')
#Select case type
selectorCaseType = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListCaseTypes']"))
selectorCaseType.select_by_visible_text('Criminal-Clerk')
#Select date search for filing date
selectorDateSearchType = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListDateFilter']"))
selectorDateSearchType.select_by_visible_text('Case Filed')
#Fill from and to date
textBoxDateFrom = driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_TextBoxDateFrom']")
textBoxDateFrom.send_keys(dateStart)
textBoxDateTo = driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_TextBoxDateTo']")
textBoxDateTo.send_keys(dateEnd)
get_cookies = driver.get_cookies()
print(get_cookies)
#Submit search
driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_ButtonSearch']").click()
#Click each case number
driver.close()