Facebook 爬虫每秒多次访问我的服务器,它似乎忽略了 Expires 标头和 og:ttl 属性。
在某些情况下,它会在 1-5 分钟内多次访问同一 og:image 资源。在一个示例中,爬虫程序在 3 分钟内使用 12 个不同的 IP 地址访问同一张图像 12 次。
我只需要记录请求 10 分钟就发现了以下示例:
一张图片的时间和爬虫IP地址列表:
2018-03-30 15:12:58 - 66.220.156.145
2018-03-30 15:13:13 - 66.220.152.7
2018-03-30 15:12:59 - 66.220.152.100
2018-03-30 15:12:18 - 66.220.155.248
2018-03-30 15:12:59 - 173.252.124.29
2018-03-30 15:12:15 - 173.252.114.118
2018-03-30 15:12:42 - 173.252.85.205
2018-03-30 15:13:01 - 173.252.84.117
2018-03-30 15:12:40 - 66.220.148.100
2018-03-30 15:13:10 - 66.220.148.169
2018-03-30 15:15:16 - 173.252.99.50
2018-03-30 15:14:50 - 69.171.225.134
og:image 是根据什么Facebook 的文档 https://developers.facebook.com/docs/sharing/webmasters#markup:
当有人将内容分享到时显示的图像的 URL
Facebook。请参阅下文了解更多信息,并查看我们的最佳实践
了解如何指定高质量预览图像的指南。
我在 og:image 中使用的图像的 Expires 标头设置为未来 +7 天。最近,我将其更改为未来+1年。这两种设置似乎都没有任何区别。爬虫似乎忽略的标头:
Cache-Control: max-age=604800
Content-Length: 31048
Content-Type: image/jpeg
Date: Fri, 30 Mar 2018 15:56:47 GMT
Expires: Sat, 30 Mar 2019 15:56:47 GMT
Pragma: public
Server: nginx/1.4.6 (Ubuntu)
Transfer-Encoding: chunked
X-Powered-By: PHP/5.5.9-1ubuntu4.23
根据脸书的对象属性文档 https://developers.facebook.com/docs/sharing/opengraph/object-properties, og:ttl 属性为:
距离重新抓取此页面还有几秒。用它来限制速率
Facebook 内容爬虫。允许的最小值为 345600
秒(4 天);如果您设置较低的值,则将使用最小值。
如果不包含此标签,则 ttl 将根据
您的网络服务器返回“Expires”标头,否则它将
默认为 7 天。
我已将此 og:ttl 属性设置为 2419200,即未来 28 天。
我一直想使用这样的东西:
header("HTTP/1.1 304 Not Modified");
exit;
但我担心 Facebook 的爬虫会忽略标题并将图像标记为已损坏 - 从而从共享故事中删除图像预览。
来自爬虫的这些请求正在传入。
有没有办法阻止爬虫这么快回来访问这些资源呢?
显示我的开放图和元属性的示例代码:
<meta property="fb:app_id" content="MyAppId" />
<meta property="og:locale" content="en_GB" />
<meta property="og:type" content="website" />
<meta property="og:title" content="My title" />
<meta property="og:description" content="My description" />
<meta property="og:url" content="http://example.com/index.php?id=1234" />
<link rel="canonical" href="http://example.com/index.php?id=1234" />
<meta property="og:site_name" content="My Site Name" />
<meta property="og:image" content="http://fb.example.com/img/image.php?id=123790824792439jikfio09248384790283940829044" />
<meta property="og:image:width" content="940"/>
<meta property="og:image:height" content="491"/>
<meta property="og:ttl" content="2419200" />