[英]Select proper element on webpage using Python - Selenium chromedriver
I am trying to write script which needs to open two boxes on webpage and get proper email address.我正在尝试编写需要在网页上打开两个框并获取正确电子邮件地址的脚本。 I believe i am not inheriting elements on webpage properly.我相信我没有正确继承网页上的元素。 Please view my code below:请在下面查看我的代码:
try:
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "body > section > section > section > div.mapAndAttrs > p:nth-child(2)")))
xxx = driver.find_element_by_css_selector("#titletextonly").text
#Click on Reply button
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.reply-button.js-only"))).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only')))
#target email address
to = driver.find_element_by_css_selector("body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside.reply-flap.js-captcha > ul > li.reply-email > p > a").text
except:
Here is sample page from which I need to extract email: https://newyork.craigslist.org/fct/cto/d/ridgefield-2003-bmw-x5-30-xdrive/7212695001.html这是我需要从中提取电子邮件的示例页面: https : //newyork.craigslist.org/fct/cto/d/ridgefield-2003-bmw-x5-30-xdrive/7212695001.html
Email is located in "reply" button and then another "show email" button.电子邮件位于“回复”按钮,然后是另一个“显示电子邮件”按钮。
Any guidance is greatly appreciated.非常感谢任何指导。
you can use:您可以使用:
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "body > section > section > section > div.mapAndAttrs > p:nth-child(2)")))
xxx = driver.find_element_by_css_selector("#titletextonly").text
#Click on Reply button
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.reply-button.js-only"))).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only')))
#target email address
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside > ul > button'))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside')))
texto = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside > ul > li.reply-email > p > a'))).text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.