【发布时间】:2016-04-30 08:22:13
【问题描述】:
我试图让 Facebook 爬虫访问网站上带有 Open Graph 标签的元信息,但它没有读取 head 标签的内部内容。
如果我回显了抓取信息,它会将 head 标签显示为:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>
<body>
...
然而,在页面的源头,头部信息包含元标记:
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="referrer" content="always" />
<meta property="fb:app_id" content="375576830972731" />
<meta property="og:site_name" content="Site Name" />
<meta property="og:title" content="Title of content" />
<meta property="og:url" content="https://website.domain.com/123456" />
<meta property="og:image" content="http://s3-us-west-1.amazonaws.com/domain/media/images/001/original/001" />
<meta property="og:description" content="Description of content" />
<meta property="og:type" content="article" />
</head>
我的控制器设置为允许“protect_from_forgery”异常,并且我确保在 robots.txt 中允许 Facebook 爬虫:
User-agent: Facebot
Allow: /
User-agent: facebookexternalhit/1.1
Allow: /
为什么 Facebook 的爬虫无法获取我标题中的元标记?
【问题讨论】:
-
你有validated你的HTML吗?示例 URL,以便我们查看问题?
标签: facebook ruby-on-rails-4 facebook-graph-api web-crawler meta-tags