简体   繁体   中英

How to to extract data from notam using selenium

from selenium import webdriver
chrome_path=r"C:\Users\Admin\Desktop\New folder\chromedriver.exe"
driver=webdriver.Chrome(chrome_path)
driver.get("https://www.notams.faa.gov/dinsQueryWeb/")
driver.find_element_by_xpath("""/html/body/div[3]/div[3]/button""").click()
search=driver.find_element_by_name("retrieveLocId")
#search=driver.find_element_by_xpath("""//*[@id="searchCriteria"]/div/input""")
ICAO=input("ENTER 4 DIGIT ICAO CODE")
search.send_keys(ICAO)
driver.find_element_by_xpath("""/html/body/table[3]/tbody/tr/td[1]/table/tbody/tr[1]/td/form/table/tbody/tr/td[2]/table/tbody/tr[5]/td/input[1]""").click()

table=len(driver.find_elements_by_xpath("""//*[@id="form1"]/div/table/tbody/tr[1]/td/table[3]/tbody/tr"""))

No basically when you click View NOTAMs , it would open a new tab, so you need to switch to new tab:

driver.find_element_by_xpath("/html/body/table[3]/tbody/tr/td[1]/table/tbody/tr[1]/td/form/table/tbody/tr/td[2]/table/tbody/tr[5]/td/input[1]").click()
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
table = len(driver.find_elements_by_xpath("//*[@id='form1']/div/table/tbody/tr[1]/td/table[3]/tbody/tr"))

should print 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