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
#2
Did you ever get this working?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Not able to sign into gmail using selenium Leo_Red 4 2,942 Nov-19-2020, 05:03 AM
Last Post: Leo_Red
  How can I enter 2 jinjia variables in this hyperlink? Ulnie 2 802 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 830 Sep-01-2020, 01:19 PM
Last Post: Justchse
  Get html body of URL rama27 6 1,505 Aug-03-2020, 02:37 PM
Last Post: snippsat
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 958 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 987 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  Why doesn't my spider find body text? sigalizer 5 2,672 Oct-30-2019, 11:35 PM
Last Post: sigalizer
  Is it possible to perform a PUT request by passing a req body instead of an ID ary 0 1,062 Feb-20-2019, 05:55 AM
Last Post: ary
  In CSV, how to write the header after writing the body? Tim 18 10,680 Jan-06-2018, 01:54 PM
Last Post: Larz60+
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 2,410 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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