如何从中提取临时电子邮件地址https://tempmail.org 使用硒

2024-05-15 21:22:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试访问:temp-mail.org,他们删除了使用API提取电子邮件的可能性,所以我尝试使用python(selenium)提取电子邮件

我正在使用下面的代码来避免被cloudflare检测到,但有时还是会被抓到

from selenium.webdriver.common.proxy import Proxy, ProxyType
from streamlit import caching
from selenium import webdriver
 
 
 
option = webdriver.ChromeOptions()
option.add_argument("user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")
driver = webdriver.Chrome(os.getcwd()+"chromedriver.exe")



PROXY =[
{"host": "104.248.123.76", "port":18080},
{"host": "136.144.54.195", "port":80}
]
 
index = int(uniform(0, len(PROXY)))
PROXY = PROXY[index]["host"]+":"+str(PROXY[index]["port"])
 
webdriver.DesiredCapabilities.CHROME['proxy']={
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "proxyType":"MANUAL",
 
}

caching.clear_cache()
driver.delete_all_cookies()

driver.get('website')

我是否需要更改获取代理的网站,或者是否有其他解决方案


Tags: fromimporthostindexosport电子邮件driver
1条回答
网友
1楼 · 发布于 2024-05-15 21:22:57

有点不清楚为什么您觉得Cloudflare将您的程序检测为机器人

要从https://temp-mail.org/提取临时电子邮件地址,可以使用以下基于Locator Strategy的解决方案:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    import win32clipboard
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get('https://temp-mail.org/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-rds icon-btn bg-theme click-to-copy copyIconGreenBtn']"))).click()
    # get clipboard data
    win32clipboard.OpenClipboard()
    data = win32clipboard.GetClipboardData()
    win32clipboard.CloseClipboard()
    print(data)
    
  • 控制台输出:

    soton18826@girtipo.com
    
  • 浏览器和控制台快照: tempmail

相关问题 更多 >