【发布时间】:2018-07-15 07:45:09
【问题描述】:
我在 python 中结合 selenium 编写了一个脚本,以从网页获取一些信息。要获得内容,有必要跨几个步骤,如accepting condition、fill in the inputbox、click on the search button 来填充结果,最后在填充的表中单击the first grid(更具体地说,第一个 tr)。只要对the first tr 发起任何点击,就会打开一个新页面(包含所需信息)。
我的脚本可以成功完成前三个步骤。我不能做的是:
perform a click on the first tr-
focus to the newly opened tab(包含我想要的信息)
要达到内容:
这是the link 关注。有一个接受按钮首先单击。然后有一个输入框
Name要填写HMC DESIGN GROUP。现在,按下搜索按钮,结果应该出现在表格的下方。从那里我需要点击第一个 tr。
这是我迄今为止尝试过的:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
link = "https://officialrecords.broward.org/AcclaimWeb/search/SearchTypeName"
def get_information(driver,url):
driver.get(url)
wait.until(EC.element_to_be_clickable((By.ID, "btnButton"))).click()
wait.until(EC.presence_of_element_located((By.ID,"SearchOnName"))).send_keys("HMC DESIGN GROUP")
wait.until(EC.presence_of_element_located((By.ID, "btnSearch"))).click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,".t-grid-content table tr"))).click()
if __name__ == "__main__":
driver = webdriver.Chrome()
wait = WebDriverWait(driver,10)
try:
get_information(driver,link)
finally:
driver.quit()
目前脚本既没有点击网格the first tr of the newly generated table 也没有抛出任何错误。它优雅地退出浏览器。
【问题讨论】:
标签: python python-3.x selenium selenium-webdriver web-scraping