Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击登录按钮后易趣网站挂起-Selenium Python_Python_Selenium_Selenium Webdriver_Web Scraping_Bots - Fatal编程技术网

单击登录按钮后易趣网站挂起-Selenium Python

单击登录按钮后易趣网站挂起-Selenium Python,python,selenium,selenium-webdriver,web-scraping,bots,Python,Selenium,Selenium Webdriver,Web Scraping,Bots,我已经编写了以下代码来登录网站。到目前为止,它只是获取网页,接受cookies,但当我试图通过单击登录按钮登录时,页面挂起,登录页面从未加载 from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, ElementNotInteractableException # Accept consent cookies def accept_cookies(browser

我已经编写了以下代码来登录网站。到目前为止,它只是获取网页,接受cookies,但当我试图通过单击登录按钮登录时,页面挂起,登录页面从未加载

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, ElementNotInteractableException


# Accept consent cookies
def accept_cookies(browser):
    try:
        browser.find_element_by_xpath('//*[@id="gdpr-banner-accept"]').click()
    except NoSuchElementException:
        print('Cookies already accepted')
        

# Webpage parameters
base_site = "https://www.ebay-kleinanzeigen.de/"

# Setup remote control browser
fireFoxOptions = webdriver.FirefoxOptions()
#fireFoxOptions.add_argument("--headless")
browser = webdriver.Firefox(executable_path = '/home/Webdriver/bin/geckodriver',firefox_options=fireFoxOptions)
browser.get(base_site)
accept_cookies(browser)

# Click login pop-up 
browser.find_elements_by_xpath("//*[contains(text(), 'Einloggen')]")[1].click()
注意:有两个登录按钮(一个弹出窗口和页面中的一个),我尝试了这两个按钮,结果相同

我做过类似的其他网站,没有问题。所以我很好奇为什么它在这里不起作用


你有没有想过为什么会这样?或者如何解决这个问题?

我稍微修改了您的代码,添加了几个可选参数,在执行时,我得到了以下结果:

  • 代码块:

    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
    
    driver.get("https://www.ebay-kleinanzeigen.de/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='gdpr-banner-accept']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Einloggen')]"))).click()
    
  • 观察:我的观察结果与您的类似,页面挂起,登录页面从未加载,如下所示:


深潜 在查看网页的链接时,您会发现一些
标记引用了具有关键字dist的JavaScripts。例如:

  • window.BelenConf.prebidFileSrc='/static/js/lib/node_modules/@ebayk/prebid/dist/prebid.10o55zon5xyi.js'
这清楚地表明,网站受到机器人管理服务提供商的保护,ChromeDriver的导航被检测到,随后被阻止


蒸馏 根据该条:

Distil通过观察网站行为和识别刮刀特有的模式,保护网站免受自动内容刮刀的攻击。当Distil在一个站点上识别出恶意bot时,它会创建一个黑名单上的行为配置文件,并部署到其所有客户。类似于机器人防火墙,Distil检测模式并做出反应

此外

“Selenium的一种模式是自动窃取网络内容”
,Distil首席执行官Rami Essaid上周在一次采访中说<代码>“尽管他们可以创建新的机器人,但我们找到了一种方法来识别他们正在使用的工具Selenium,因此无论他们在该机器人上迭代多少次,我们都会阻止Selenium。我们现在使用Python和许多不同的技术来实现这一点。一旦我们看到一种类型的机器人出现了一种模式,我们就会对他们使用的技术进行逆向工程,并将其识别为恶意的。


参考文献 您可以在以下内容中找到一些详细的讨论:


请为您的答案提供一些上下文。这可能有助于其他读者轻松理解您的方法。
from selenium import webdriver
from selenium_stealth import stealth
import time

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")

# options.add_argument("--headless")

options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r"C:\Users\DIPRAJ\Programming\adclick_bot\chromedriver.exe")

stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )

url = "https://bot.sannysoft.com/"
driver.get(url)
time.sleep(5)
driver.quit()