Home > Net >  retrieving chrome driver element data from returned form
retrieving chrome driver element data from returned form

Time:03-16

I'm trying to build a simple scraper with selenium to retrieve zip code for a given address, city, ST from this USPS tool: enter image description here

CodePudding user response:

I have no idea why you try to use get_attributes.

To get some attributes this page would need <strong name="..." value="..."> but it has only <strong>

If you want tag name then use zipcode.tag_name
and if you want text 15219-1820 inside <strong> </strong> then use zipcode.text

zipcode = driver.find_element(By.XPATH, '//*[@id="zipByAddressDiv"]/ul/li[1]/div[1]/p[3]/strong')

print(zipcode.tag_name)
print(zipcode.text)

CodePudding user response:

(Referencing off the image)
You could instead get the element zipcode-by-address and get it's child classes and find the strong

driver = webdriver.Firefox()
... # navigation stuff here.
element = driver.find_element_by_class_name("zipcode-by-address")
all_children_by_xpath = header.find_elements_by_xpath(".//*") # https://stackoverflow.com/questions/24795198/get-all-child-elements
  • Related