Scrape Verify link Href From Sites

Question:

I want to get the Verify href from GmailnatorInbox and this site contains the href discord verify which is the following Discord Verify HREF

I want to get this href using bs4 and pass it into a selenium driver link like driver.get(url) the url being the href ofc.

Can someone make some code to scrape the href from the gmailnator inbox please? I did try the page source however the page source does not contain the href.

This is the code I have written to get the href but the href that I require (discord one) is in a frame source so I think that’s why it doesnt come up.

UPDATE! EVERYTHING IS DONE AND FIXED

driver.get('https://www.gmailnator.com/inbox/#[email protected]')
time.sleep(6)
driver.find_element_by_xpath('//*[@id="mailList"]/tbody/tr[2]/td/a/table/tbody/tr/td[1]').click()
time.sleep(4)
url = driver.current_url
email_for_data = driver.current_url.split('/')[-3]
print(url)
time.sleep(2)
print('Getting Your Discord Verify link')
print('Time To Get Your Discord Link')
soup = BeautifulSoup(requests.get(url).text, "lxml")
data_email = soup.find("")
token = soup.find("meta", {"name": "csrf-token"})["content"]
cf_email = soup.find("a", class_="__cf_email__")["data-cfemail"]

endpoint = "https://www.gmailnator.com/mailbox/get_single_message/"

data = {
    "csrf_gmailnator_token": token,
    "action": "get_message",
    "message_id": url.split("#")[-1],
    "email": f"{email_for_data}",
}

headers = {
    "referer": f"https://www.gmailnator.com/{email_for_data}/messageid/",
    "cookie": f"csrf_gmailnator_cookie={token}; ci_session={cf_email}",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
                  "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 "
                  "YaBrowser/21.3.0.740 Yowser/2.5 Safari/537.36",
    "x-requested-with": "XMLHttpRequest",
}

r = requests.post(endpoint, data=data, headers=headers)
the_real_slim_shady = (
    BeautifulSoup(r.json()["content"], "lxml")
    .find_all("a", {"target": "_blank"})[1]["href"]
)
print(the_real_slim_shady)
Asked By: SomeGuyCoding

||

Answers:

You can fake it all with pure requests to get the Verify link. First, you need to get the token and the cf_email values. Then, things are pretty straightforward.

Here’s how to get the link:

import requests
from bs4 import BeautifulSoup

url = "https://www.gmailnator.com/geralddoreyestmp/messageid/#179b454b4c482c4d"
soup = BeautifulSoup(requests.get(url).text, "lxml")

token = soup.find("meta", {"name": "csrf-token"})["content"]
cf_email = soup.find("a", class_="__cf_email__")["data-cfemail"]

endpoint = "https://www.gmailnator.com/mailbox/get_single_message/"

data = {
    "csrf_gmailnator_token": token,
    "action": "get_message",
    "message_id": url.split("#")[-1],
    "email": "geralddoreyestmp",
}

headers = {
    "referer": "https://www.gmailnator.com/geralddoreyestmp/messageid/",
    "cookie": f"csrf_gmailnator_cookie={token}; ci_session={cf_email}",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
                  "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 "
                  "YaBrowser/21.3.0.740 Yowser/2.5 Safari/537.36",
    "x-requested-with": "XMLHttpRequest",
}

r = requests.post(endpoint, data=data, headers=headers)
the_real_slim_shady = (
    BeautifulSoup(r.json()["content"], "lxml")
    .find_all("a", {"target": "_blank"})[1]["href"]
)
print(the_real_slim_shady)

Output (your link will be different!):

https://click.discord.com/ls/click?upn=qDOo8cnwIoKzt0aLL1cBeARJoBrGSa2vu41A5vK-2B4us-3D77CR_3Tswyie9C2vHlXKXm6tJrQwhGg-2FvQ76GD2o0Zl2plCYHULNsKdCuB6s-2BHk1oNirSuR8goxCccVgwsQHdq1YYeGQki4wtPdDA3zi661IJL7H0cOYMH0IJ0t3sgrvr2oMX-2BJBA-2BWZzY42AwgjdQ-2BMAN9Y5ctocPNK-2FUQLxf6HQusMayIeATMiTO-2BlpDytu-2FnIW4axB32RYQpxPGO-2BeHtcSj7a7QeZmqK-2B-2FYkKA4dl5q8I-3D
Answered By: baduker