我正在尝试在网站上运行我的 selenium javascriptbet365.com https://bet365.com。我使用的是 Firefox (geckodriver),我尝试了无头模式和正常模式,但为了理解/调试问题,非无头模式很有帮助。
这是代码:
const driver = await new Builder().forBrowser("firefox").build();
await driver.get("https://bet365.com");
The problem is that the site is not loading:
5分钟后我就得到了错误
TimeoutError: TimedPromise timed out after 300000 ms
at Object.throwDecodedError (C:\1_code\RFB\git\webscraper-srv\node_modules\selenium-webdriver\lib\error.js:517:15)
at parseHttpResponse (C:\1_code\RFB\git\webscraper-srv\node_modules\selenium-webdriver\lib\http.js:671:13)
at Executor.execute (C:\1_code\RFB\git\webscraper-srv\node_modules\selenium-webdriver\lib\http.js:597:28)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Driver.execute (C:\1_code\RFB\git\webscraper-srv\node_modules\selenium-webdriver\lib\webdriver.js:729:17)
at async C:\1_code\RFB\git\webscraper-srv\scripts\seleniumUtils.js:190:3
at async XWrap.<anonymous> (C:\1_code\RFB\git\webscraper-srv\scripts\utils.js:127:60)
at async XWrap.<anonymous> (C:\1_code\RFB\git\webscraper-srv\scripts\utils.js:127:60)
at async XWrap.<anonymous> (C:\1_code\RFB\git\webscraper-srv\scripts\utils.js:127:60)
at async XWrap.<anonymous> (C:\1_code\RFB\git\webscraper-srv\scripts\utils.js:127:60) {
remoteStacktrace: 'WebDriverError@chrome://marionette/content/error.js:181:5\n' +
'TimeoutError@chrome://marionette/content/error.js:450:5\n' +
'bail@chrome://marionette/content/sync.js:229:19\n'
我尝试使用硒访问不同的网站,它们工作得很好,所以我认为我的设置没有问题。
如果我尝试使用普通的 Firefox 浏览器访问该网站,它也能正常工作。
我还尝试在浏览器中手动搜索程序打开的页面,这导致了另一个无限循环。但是在这个浏览器中手动打开由selenium打开的其他页面效果很好。
网页服务器是否可以检测使用selenium启动的浏览器?我一直认为检测网络爬虫的唯一方法是查看它的访问频率以及爬虫在页面上的点击次数,但这是我第一次使用 Selenium 访问该页面......
如果服务器不允许此类请求,是否有任何方法仍然可以从此网页抓取数据?我也已经尝试以无头模式打开它......
This is the (entire) Firefox Network tab when its stuck loading (sometimes it looks a little different):
This is the (begin of the) Firefox Network tab when its loaded normally:
我圈出了可能导致问题的请求。在浏览器的左下角,它一直告诉我它正在Transfering data from ff.kis.v2.scr.kaspersky-labs.com
。我尝试在我的机器上停用卡巴斯基,并让程序在没有卡巴斯基的机器上运行,所以我不太确定为什么提出这个请求。它可能需要对 https 验证做一些事情,但我不确定。
Another interesting thing is that the response of the first request to www.bet365.com/
looks like this (even with selenium):
Meaning that it does actually reach the server but it just sends a loading screen. Also the following requests get the same response as with the normal browser. Only the requests with status 101
don't give back any response, unlike with the normal browser.
最后有趣的是这个请求www.bet365.com/increment?desktop-site-loaded_11=1
。它仅在使用 selenium 浏览器启动时生成,而不是在使用普通浏览器打开站点时生成。这可能意味着它不是加载问题,而是主动阻止请求并告诉后端增加被阻止请求的计数器。
有什么想法可以让代码正常工作或者为什么会出现这个问题?