【问题标题】:Bypass Cloudfare using Python Selenium使用 Python Selenium 绕过 Cloudflare
【发布时间】:2021-08-05 21:21:43
【问题描述】:

我只是想绕过使用 selenium python 的 cloudfare 服务我已经编写了代码但它不起作用

这是我的代码:

import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r".\chromedriver.exe")
driver.maximize_window()
driver.get('https://poocoin.app/tokens/0xef2ec90e0b8d4cdfdb090989ea1bc663f0d680bf')

当我运行代码时,我会卡在 cloudfare 中

查看截图:

当我手动打开它时,它看起来像这样

【问题讨论】:

  • “但它不起作用”是什么意思?即使我手动打开该链接,您看到的屏幕也会显示。
  • 当我手动打开它会完美打开
  • 嗨,我已经更新了问题,请检查一下希望你明白我想说什么

标签: python selenium selenium-webdriver web-scraping selenium-chromedriver


【解决方案1】:

我也看到了 cloudfare 屏幕。
您只需要添加一个等待条件,直到出现 poocoin 站点本身。

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

wait.until(EC.url_to_be('https://poocoin.app/tokens/0xef2ec90e0b8d4cdfdb090989ea1bc663f0d680bf'))

之后,您可以继续您的流程。
您也可以等待其他一些条件。例如title to be 或该页面上存在某些元素。

【讨论】:

  • 它不起作用,因为驱动程序卡在 cloudfare 他们不会继续实际链接
  • 你试过我写的吗?你定义了等待超时吗?
  • WebDriverWait(驱动程序,1000).until(EC.url_to_be('poocoin.app/tokens/…))
  • 我已将超时设置为 1000。
  • 这里显示的driver.get('https://poocoin.app/tokens/0xef2ec90e0b8d4cdfdb090989ea1bc663f0d680bf') 行之后的代码是什么?
猜你喜欢
  • 2022-09-27
  • 2021-09-18
  • 2022-09-27
  • 2021-04-12
  • 1970-01-01
  • 2021-07-24
  • 2016-11-19
  • 2014-01-22
  • 2022-07-28
相关资源
最近更新 更多