如何知道你是否因网络抓取而被网站屏蔽



我在一个网站上使用了这个beautifulsoup代码:

headers = ({'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'})
funda = "https://www.funda.nl/koop/amsterdam/"
response = get(funda, headers=headers)
print(response)
html_soup = BeautifulSoup(response.text, 'html.parser')
print(response.text)

我收到了这个回复。回复文本:

<Response [200]>
<!DOCTYPE html>
<html>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="refresh" content="10; url=/distil_r_captcha.html?requestId=01fe7635-8c6e-404f-b905-fd8d854fa40c&httpReferrer=%2Fkoop%2Famsterdam%2F" />
<script type="text/javascript">
(function(window){
try {
if (typeof sessionStorage !== 'undefined'){
sessionStorage.setItem('distil_referrer', document.referrer);
}
} catch (e){}
})(window);
</script>
<script type="text/javascript" src="/fundadst.rvezxdcvwbzdewcsbar.js" defer></script><style type="text/css">#d__fFH{position:absolute;top:-5000px;left:-5000px}#d__fF{font-family:serif;font-size:200px;visibility:hidden}#suuazwruefzeaa{display:none!important}</style></head>
<body>
<div id="distilIdentificationBlock">&nbsp;</div>
</body>
</html>

我被挡住了吗?这个街区是永久性的吗?我能做点什么吗?

谢谢

这看起来像是在试图使用python请求库抓取一个javascript渲染的网站?这个库只能抓取静态站点,这就是为什么您在响应中收到JS块的原因。

您应该考虑切换到以下软件包之一:

  • Selenium(使用无头浏览器(
  • Scrapy(使用蜘蛛在网上爬行(

还有其他几个库可以封装chrome驱动程序,但维护的库并不多。

这里有一个关于硒刮的中等教程:https://medium.com/@hoppy/how-to-test-or-scrape-javascript-rendered-websites-with-python-selenium-a-beginer-step-by-c137892216aa

下面是一个使用网络爬虫进行抓取的中等教程:https://medium.com/@djerahahmedrafik/web-scrapping-basials-using-scrapy-84a1e64b5ec

希望这能有所帮助。

最新更新