Home > Back-end >  NoSuchElementException: Message: no such element: Unable to locate element: {"method":&quo
NoSuchElementException: Message: no such element: Unable to locate element: {"method":&quo

Time:08-12

How do I copy text from a website that is protected? gives error if you try to copy by xpath, name and tag.

This is the error I get when I try using XPath (obs: inside the site there is a "copy" button that if clicked, copies the text)

enter image description here

This is my code:

enter image description here

On the website it says: Don't worry about spam, email advertisements, hackers and robot attacks anymore. I think that's why it's giving an error. Someone knows what it is?

CodePudding user response:

This is how you obtain that email address :

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time as t

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('disable-notifications')
chrome_options.add_argument("window-size=1280,720")

webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary
browser = webdriver.Chrome(service=webdriver_service, options=chrome_options)

url = 'https://temp-mail.org'

browser.get(url) 
email_field = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "mail")))
email_field.click()
t.sleep(1)
email_address = email_field.get_attribute('value')
print('email address:', email_address)

Result printed in terminal:

email address: [email protected]

Selenium setup is for linux, but you just have to observe the imports, as well as the part after defining the browser. Selenium documentation can be found at https://www.selenium.dev/documentation/

  • Related