简体   繁体   中英

Selenium Webdriver switch to another window and parse data

https://officialrecords.broward.org/AcclaimWeb/search/SearchTypeName

点击BANKATLANTIC

Click on BANKATLANTIC

在此处输入图片说明

How to extract the TransactionItemId? # under DocLink

How to extract the text from the 1st document?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from time import sleep

driverurl = "https://officialrecords.broward.org/AcclaimWeb/search/SearchTypeName"
RecordDateInput = "8/15/2017"

driver = webdriver.Chrome()
driver.get(driverurl)
driver.find_element_by_id("btnButton").click()

driver.find_element_by_id("Direct").click() # Grantor

Name = "ba"
driver.find_element_by_id("SearchOnName").send_keys(Name)

DocType = "RELEASE/REVOKE/SATISFY OR TERMINATE (RST)"
driver.find_element_by_id("DocTypesDisplay-input").clear()
sleep(1)
driver.find_element_by_id("DocTypesDisplay-input").send_keys(DocType)

driver.find_element_by_id("RecordDateFrom").clear()
driver.find_element_by_id("RecordDateFrom").send_keys(RecordDateInput)
driver.find_element_by_id("RecordDateTo").clear()
driver.find_element_by_id("RecordDateTo").send_keys(RecordDateInput)

driver.execute_script("return arguments[0].scrollIntoView();", driver.find_element_by_id("btnSearch"))
driver.find_element_by_id("btnSearch").click()
sleep(7)

driver.find_elements_by_class_name("rowNumClass")[0].click()
sleep(3)

#######################################################
# solution:

driver.switch_to_window(driver.window_handles[1])
sleep(3)

html = driver.page_source 
soup = BeautifulSoup(html, "lxml") 

TransactionItemId = soup.findAll("div", { "class" : "listDocDetails" })[-1].find("a")['onclick'].split("'")[1]

The only way I can see to get the element that contains $600,000 is to get the element that contains the "Consideration:" label and then find the following DIV that contains the dollar amount. The only way to find an element by contained text is to use an XPath. The one below works.

//div[@class='detailLabel'][contains(.,'Consideration:')]/following-sibling::div

Try this:

driver.switch_to_window(driver.window_handles[1])
sleep(3)

html = driver.page_source 
soup = BeautifulSoup(html, "lxml") 

TransactionItemId = soup.findAll("div", { "class" : "listDocDetails" })[-1].find("a")['onclick'].split("'")[1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM