Cloudflare和很多其他网站一样会检测访问是否为Selenium bot,其中一项为检测Selenium运行时出现的特有js变量。
这里主要包括了是否含有"selenium"/ "webdriver"的变量或者含有"$cdc_"/"$wdc_"的文件变量。
每个driver的检测机制会不一样,此处给出的方案基于chromedriver。
1. Undetected-chromedriver
非常简单好用的包,直接pip安装,如下初始化driver即可,之后就像正常Selenium使用即可。
import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://nowsecure.nl')
2. 直接修改chromedriver executable
将key变量修改成任意不含"cdc"的字符。
/**
* Returns the global object cache for the page.
* @param {Document=} opt_doc The document whose cache to retrieve. Defaults to
* the current document.
* @return {!Cache} The page's object cache.
*/
function getPa