Learner Learner - 12 days ago 12
Python Question

Selenium Python code

This is my very first time trying to scrape data from a website using Selenium. Fortunately I have got Selenium and Chrome to coordinate and the desired website opens.Once it opens up, I want to tell Python to click '

SEARCH
' leaving the empty box blank (next to contains) and then tell Python to export the results ' and save the
xlsx
file as
result_file
. I do not know why the snippet is blowing up. Please provide your kind assistance.

from selenium import webdriver

driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe")
driver.get("https://etrakit.friscotexas.gov/Search/permit.aspx")

number_option = driver.find_element_by_id("cplMain_btnSearch")
number_option.click()

search_button = driver.find_element_by_id("cplMain_btnExportToExcel")
search_button.click()

result_file = open("result_file.xlsx", "w")

driver.close()
result_file.close()

Answer

Looking at the source of that page, the ID of the search button is "cplMain_btnSearch" not "SEARCH". And the Export button is "cplMain_btnExportToExcel".

Comments