Home > Enterprise >  Iterate through alphabet using send.key on selenium to scrape info
Iterate through alphabet using send.key on selenium to scrape info

Time:12-19

Right now my code is set up to scrape through all the last names that start with 'Z'

 query = ['Z']
 for letter in query:
    url = "https://hsba.org/HSBA_2020/For_the_Public/Find_a_Lawyer/HSBA_2020/Public/Find_a_Lawyer.aspx"
    driver.get(url)
    #input from query 
    element = driver.find_element(By.CSS_SELECTOR,'#txtDirectorySearchLastName')
    element.send_keys(letter)

I need it to loop through the whole alphabet and get all the text info on each page.

I tried searching for help and am not sure where to start... (Disclaimer: very new to coding)

CodePudding user response:

import string
alphabets=list(string.ascii_lowercase)
for alph in alphabets:
    url = "https://hsba.org/HSBA_2020/For_the_Public/Find_a_Lawyer/HSBA_2020/Public/Find_a_Lawyer.aspx"
    driver.get(url)
    #input from query 
    element = driver.find_element(By.CSS_SELECTOR,'#txtDirectorySearchLastName')
    element.send_keys(alph)

If you need to loop all the letters just get all letters using string.ascii_lowercase and loop them.

  • Related