Python Forum
find a hyperlink in Gmail body python 3(imap and selenium)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find a hyperlink in Gmail body python 3(imap and selenium)
#1
I am making a program to automatically read emails and click automatically a hyperlink in that email body.

A taxi company provides contractions from email. immediately need to click on link in email.

I am using imaplib , selenium , re to code this. I successfully coded the login to email using imaplib and read mail.

Now i need to get hyperlink from mail.(hyperlink text is confirm)
i used a code for getting hyperlink but hyperlink is wrong.

show URL with more other characters.....url not working...
if have more hyperlinks how get a one hyperlink. can get a hyperlink using link text?


code given below
import imaplib 
import email

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('[email protected]', '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
raw_email = str(raw_email)
import re
print(re.search("(?P<url>https?://[^\s]+)", raw_email).group("url"))
Reply


Messages In This Thread
find a hyperlink in Gmail body python 3(imap and selenium) - by taomihiranga - Mar-13-2019, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [BeautifulSoup] Find </body>? Winfried 3 1,240 Jul-21-2023, 11:25 AM
Last Post: Gaurav_Kumar
  Selenium suddenly fails to find element Pavel_47 3 6,200 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  Gmail API - Error 400: redirect_uri_mismatch Depp 1 1,542 Jun-12-2022, 10:42 AM
Last Post: snippsat
  Not able to sign into gmail using selenium Leo_Red 4 5,692 Nov-19-2020, 05:03 AM
Last Post: Leo_Red
  How can I enter 2 jinjia variables in this hyperlink? Ulnie 2 2,055 Oct-06-2020, 01:58 PM
Last Post: DeaD_EyE
  How to send notifications to gmail from contact form using Django and pushbullet Justchse 0 1,840 Sep-01-2020, 01:19 PM
Last Post: Justchse
  Get html body of URL rama27 6 3,355 Aug-03-2020, 02:37 PM
Last Post: snippsat
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 1,994 May-02-2020, 11:21 AM
Last Post: rajeev1729
  Send email to gmail after user fill up contact form and getting django database updat Man_from_India 0 2,070 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  Why doesn't my spider find body text? sigalizer 5 4,297 Oct-30-2019, 11:35 PM
Last Post: sigalizer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020