简体   繁体   English

使用 Python 在网页上选择适当的元素 - Selenium chromedriver

[英]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.

相关问题 无法使用 Selenium、Python 和 ChromeDriver 访问元素 - Unable to access the element using Selenium , Python and ChromeDriver 使用Selenium Python从列表中选择网页中的特定元素 - Select a particular element in a webpage from list using selenium python 在python中使用Selenium chromedriver - Using selenium chromedriver with python python selenium chromedriver xpath“没有这样的元素” - python selenium chromedriver xpath “no such element” 使用 Selenium Chromedriver 和 python 我如何点击这个元素? - Using Selenium Chromedriver with python how do i click this element? 使用 python selenium chromedriver 从源中选择隐藏的选项值 - Select hidden option value from source using python selenium chromedriver 在 selenium/python/ubuntu 中使用 chromedriver - Using chromedriver with selenium/python/ubuntu selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法使用带有Python的Selenium ChromeDriver Chrome找到元素 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element using Selenium ChromeDriver Chrome with Python Selenium 元素不可交互按钮(Python、Windows、Chromedriver) - Selenium element not interactable button (Python, Windows, Chromedriver) 在 python 中,使用 selenium 和 chromedriver 无法通过 id 找到元素 - cant find element by id with selenium and chromedriver in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM