简体   繁体   English

Selenium python:如何找到网页上的每封电子邮件?

[英]selenium python: How do I find every email on a webpage?

The website doesn't show the email addresses as text, there are buttons that open up an email box, but the email addresses are shown in the source code. 该网站未将电子邮件地址显示为文本,但是有一些按钮可以打开电子邮件框,但是电子邮件地址显示在源代码中。

Each email is in this type of html code: 每封电子邮件都是这种html代码类型:

<a onclick="CC('palthoff@mcpaz.com', '', '','','');" href="#"><img src="/cpd/images/icons/email_yellow_sm.gif" border="0"></a>

I can get to the element by xpath: 我可以通过xpath进入元素:

email = browser.find_element_by_xpath("//*[@id="row2FC"]/td[2]/div/a")

But when I "print email.text" nothing shows up. 但是,当我“打印email.text”时,没有任何显示。 I know that it would only print the text if it was shown on the page, but then how could I print the email address shown in "onclick"? 我知道,只有在页面上显示文本时,它才会打印文本,但是如何打印“ onclick”中显示的电子邮件地址? onclick="CC('the email address)' onclick =“ CC('电子邮件地址)'

I want to grab every email address from this website, but I can't figure out how to print that text. 我想从这个网站上获取每个电子邮件地址,但是我不知道如何打印该文本。

Your help is greatly appreciated. 非常感谢您的帮助。 Sorry if this is elementary, I've google searched my issue and couldn't find what I was looking for. 抱歉,如果这是基本知识,我已经在Google上搜索了我的问题,但是找不到我想要的东西。

To print the text of the email, you could slice the string returned by the get_attribute method in your own answer: 要打印电子邮件的文本,您可以在自己的答案中对get_attribute方法返回的字符串进行切片:

emails = browser.find_elements_by_tag_name("a")

for x in range(0,len(emails)):
    code = emails[x].get_attribute("onclick")
    email = code[4:len(code)-17]
    print email

I figured it out. 我想到了。

Code is below: 代码如下:

emails = browser.find_elements_by_tag_name("a")

for x in range(0,len(emails)):
    code = emails[x].get_attribute("outerHTML")
    print code

It prints the full outer HTML though. 不过,它会打印完整的外部HTML。 Is there any way to parse what prints? 有什么办法可以解析出什么印刷品?

<a onclick="CC('dbennett@realdevelopment.com', '', '','','');" href="#"><img src

To remove everything but the email? 要删除电子邮件以外的所有内容?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用chromedriver使用硒在网页中找到这些特定元素? - How do I find these particular elements in a webpage, with selenium using chromedriver? How do I test every link on a webpage with Selenium using Pytho and pytest or Selenium Firefox IDE? - How do I test every link on a webpage with Selenium using Pytho and pytest or Selenium Firefox IDE? 如何从网页中检索带有 python selenium 的链接? - How do I retrieve this link with python selenium from a webpage? 如何使用 Selenium 和 Python 获取网页中的结果数量? - How do I get the number of results in a webpage with Selenium and Python? 如何使用python硒单击网页上的Javascript按钮 - How do I click a Javascript button on a webpage using python selenium 如何在Python中找到元素[Selenium] - How do I find an element in Python[Selenium] Python - 如何在没有课程的网页上找到链接? - Python - How do I find a link on webpage that has no class? 如何下载每个 Gmail email 和 Python? - How do I download every Gmail email with Python? 在网页 selenium python 上查找 xpath - Find xpath with on webpage selenium python 我想使用 Selenium 和 Python 在网页中查找元素,如何获取输入值? - I wanna find an element in a webpage using Selenium and Python, how can I obtain the input value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM