小编典典

无法加载资源:服务器通过Selenium使用ChromeDriver Chrome响应状态为429(请求过多)和404(未找到)

selenium

我正在尝试在python中使用selenium构建刮板。Selenium
Webdriver打开窗口并尝试加载页面,但突然停止加载。我可以在本地chrome浏览器中访问相同的链接。

这是我从网络驱动程序获得的错误日志:

{'level': 'SEVERE', 'message': 'https://shop.coles.com.au/a/a-nsw-metro-rouse-hill/everything/browse/baby/nappies-changing?pageNumber=1 - Failed to load resource: the server responded with a status of 429 (Too Many Requests)', 'source': 'network', 'timestamp': 1556997743637}

{'level': 'SEVERE', 'message': 'about:blank - Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME', 'source': 'network', 'timestamp': 1556997745338}

{'level': 'SEVERE', 'message': 'https://shop.coles.com.au/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint - Failed to load resource: the server responded with a status of 404 (Not Found)', 'source': 'network', 'timestamp': 1556997748339}

我的剧本:

from selenium import webdriver
import os

path = os.path.join(os.getcwd(), 'chromedriver')
driver = webdriver.Chrome(executable_path=path)

links = [
    "https://shop.coles.com.au/a/a-nsw-metro-rouse-hill/everything/browse/baby/nappies-changing?pageNumber=1",
    "https://shop.coles.com.au/a/a-nsw-metro-rouse-hill/everything/browse/baby/baby-accessories?pageNumber=1",
    "https://shop.coles.com.au/a/a-nsw-metro-rouse-hill/everything/browse/baby/food?pageNumber=1",
    "https://shop.coles.com.au/a/a-nsw-metro-rouse-hill/everything/browse/baby/formula?pageNumber=1",
]


for link in links:
    driver.get(link)

阅读 960

收藏
2020-06-26

共1个答案

小编典典

429请求太多

HTTP 429太多请求响应状态代码指示用户在给定的时间内发送了太多请求(“速率限制”)。响应表示应包含说明条件的详细信息,并且可以包含Retry- After指示发出新请求之前要等待多长时间的标头。

当服务器受到攻击或仅从单方接收到大量请求时,以 429
状态码响应每个请求都会消耗资源。因此,不需要服务器使用429状态码。当限制资源使用时,仅断开连接或采取其他步骤可能更合适。


找不到404

HTTP 404找不到客户端错误响应代码表明服务器找不到请求的资源。在浏览器中,这意味着无法识别URL。在API中,这也可能意味着端点有效,但是资源本身不存在。服务器也可以发送此响应而不是403,以隐藏来自未授权客户端的资源。由于此响应代码在网络上经常发生,因此可能是最著名的响应代码。

一个404状态代码并不表示资源是否是暂时或永久丢失。但是,如果资源被永久删除,410 (Gone)则应使用a代替404状态。此外,404如果未找到所请求的资源使用状态代码,是否不存在,或者如果有一个401403说,出于安全原因,该服务要掩盖。


分析

当我尝试使用您的代码块时,我遇到了类似的后果。如果您检查网页DOM树,您会发现相当多的标签都带有关键字 dist* 。举个例子: *

  • <link rel="shortcut icon" type="image/x-icon" href="/wcsstore/ColesResponsiveStorefrontAssetStore/dist/30e70cfc76bf73d384beffa80ba6cbee/img/favicon.ico">
  • <link rel="stylesheet" href="/wcsstore/ColesResponsiveStorefrontAssetStore/dist/30e70cfc76bf73d384beffa80ba6cbee/css/google/fonts-Source-Sans-Pro.css" type="text/css" media="screen">
  • 'appDir': '/wcsstore/ColesResponsiveStorefrontAssetStore/dist/30e70cfc76bf73d384beffa80ba6cbee/app'

术语 dist 的存在明确表明该网站受 Bot Management 服务提供商 Distil
Networks的
保护,并且 ChromeDriver
的导航被检测到并随后 被阻止


distillation

根据文章“ 确实有关于Distil.it…的东西:”

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

进一步,

"One pattern with **Selenium** was automating the theft of Web content"Distil首席执行官拉米·埃赛伊(Rami Essai)上周在接受采访时表示。 "Even though they can create new bots, we figured out a way to identify Selenium the a tool they're using, so we're blocking Selenium no matter how many times they iterate on that bot. We're doing that now with Python and a lot of different technologies. Once we see a pattern emerge from one type of bot, then we work to reverse engineer the technology they use and identify it as malicious".


2020-06-26