【问题标题】:find a hyperlink in Gmail body python 3在 Gmail 正文 python 3 中查找超链接
【发布时间】:2019-03-12 18:57:14
【问题描述】:

我正在制作一个程序来自动阅读电子邮件并自动单击该电子邮件正文中的超链接。

一家出租车公司通过电子邮件提供收缩服务。立即需要点击电子邮件中的链接。

我正在使用 imaplib 、 selenium 、 re 来编写代码。 我使用 imaplib 成功将登录信息编码为电子邮件并阅读邮件。

现在我需要从邮件中获取超链接。(确认超链接文本) 下面给出的代码

import imaplib 
import email

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('xxxxxxxxxx@gmail.com', 'xxxxxxxx')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.

result, data = mail.search(None, "ALL")

ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
latest_email_id = id_list[-1] # get the latest

result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID

raw_email = data[0][1] # here's the body, which is raw text of the whole email
# including headers and alternate payloads
print(raw_email)

【问题讨论】:

    标签: python-3.x selenium gmail-imap imaplib


    【解决方案1】:

    对于每封电子邮件,请尝试以下操作:

    print(re.search("(?P<url>https?://[^\s]+)", myString).group("url"))
    

    【讨论】:

      猜你喜欢
      • 2011-06-22
      • 1970-01-01
      • 2010-10-17
      • 2011-10-08
      • 2018-08-05
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多