【发布时间】:2014-11-28 11:47:50
【问题描述】:
我有一个节点服务器正在运行并监听端口 8080。有一个活跃的 mod_rewrite 规则将机器人重定向到这个端口。
RewriteCond %{HTTP_USER_AGENT} (googlebot|adsbot-google|bingbot|msnbot|psbot|gigabot|twitterbot|linkedinbot|yahoo-mmcrawler|pingdom\.com_bot) [NC]
RewriteRule ^ http://127.0.0.1:8080%{REQUEST_URI} [P]
节点脚本依赖 phantomjs 脚本打开 Bot 请求的任何 URL 并返回内容。
代码取自这里http://backbonetutorials.com/seo-for-single-page-apps/
我通过在本地机器上运行 phantomjs 并使用相同的 phantomjs 代码直接请求我的网页来测试这一点。 结果和“crawl as google”表示的一样(google站长工具),就是phantomjs没有正确服务CSS和JS文件。
CSS 文件只包含
<html><head></head><body></body></html>
并且没有实际的 CSS 内容。 JS文件有
<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
在任何 JS 代码之前插入。
因此,当 google 尝试抓取和呈现页面时,布局被破坏,并引发 JS 错误。
有什么提示吗?谢谢。
【问题讨论】:
-
嘿,你解决了吗?我有同样的问题。谢谢。
标签: node.js web-crawler phantomjs single-page-application