I am working on speeding up Selenium web scraping by replacing implicitly_wait
to WebDriverWait
with send_keys
and click
. I am a little confused on how to achieve that.
This is my code for inplicitly_wait
:
def ncd_web_scraping(df):
df['new_column'] = 'Not_sure'
url = 'url'
for i in df.index:
driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get(url)
name = driver.find_element_by_xpath('//*[@id="person"]')
name.send_keys(df.loc[i, 'Name'])
state = driver.find_element_by_xpath('//*[@id="state"]')
state.send_keys(df.loc[i, 'State'])
botton = driver.find_element_by_xpath('/html/body/div[2]/form/button')
botton.click()
soup = BeautifulSoup(driver.page_source, 'html.parser')
if soup.find('h5'):
df.loc[i, 'new_column'] = 'Yes'
else:
df.loc[i, 'new_column'] = 'No'
return df
Can anyone help me with how to webDriveWait
to rewrite the code?
I appreciate your help.