如何从以下元素获取电子邮件ID?

时间:2017-07-02 10:17:32

标签: python-3.x selenium selenium-webdriver web-scraping web-crawler

如何使用发送按钮获取电子邮件ID?因为任何电子邮件都可以按下按钮进行传输,所以我认为可能有任何方法可以捕获请求。我无法知道我的剧本应该如何达到目的。谢谢你看看它。

该页面上该电子邮件按钮的图片如下:

enter image description here

发送电子邮件的Html元素位于以下部分:

<div class="col-sm-19 businessCapsule--callToAction">
<a itemprop="url" href="/customerneeds/sendenquiry/sendtoone/100040429645000120" class="btn btn-blue" data-tracking="ENQUIRY:SEND">Send Email</a>
<a itemprop="url" rel="nofollow noopener" href="http://www.redplanetpizza.com" data-tracking="AP:CN:WL" target="_blank" class="btn btn-blue">Visit Website</a>
<div id="hideFullMap" class="btn btn-blue is-active utils-hidden" role="button" tabindex="0">Hide the Map</div><button id="showFullMap" class="btn btn-blue businessCapsule--mapDirections" data-stoplink="true">Map &amp; Directions</button><span itemscope="" itemtype="http://schema.org/Map" class="utils-hidden"><span itemprop="url">https://www.yell.com/biz/red-planet-pizza-london-3432962/#view=map</span></span>
</div>

我在我的剧本下面粘贴到目前为止我写的:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.yell.com/biz/red-planet-pizza-london-3432962/')
button = driver.find_elements_by_xpath('//a[contains(@class, "btn-blue")]')[2]
button.click()
print(button.text)

我得到的结果是:

Email: Send Email

1 个答案:

答案 0 :(得分:0)

最后,安德森先生通过不同的建议为我提供了答案。这个答案是针对那些偶然遇到这样的问题的人,就像我在这里遇到的那样,碰巧看到这个话题。

import requests

link = "https://www.yell.com/customerneeds/sendenquiry/sendtoone/"
payload = {'message':'Testing whether this email really works.','senderPostcode':'GL51 0EX','enquiryTimeframe':'withinOneMonth','senderFirstName':'mth','senderLastName':'iqbal','senderEmail':'habibrahman@gmail.com','senderEmailConfirm':'habibrahman@gmail.com','uniqueAdId':'100040429645000060','channel':'desktop','ccSender':'true','marketing':'on'}
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36'}
response = requests.post(link, data = payload, headers = headers)
email_elem= response.json()
email_ID = email_elem["emailToCustomerUUID"]
print(email_ID)

结果如下:

Email-ID: 5a255d5f-3cc5-491d-87ac-9d21e652ec4b