如何获得Google的知识图谱“人们也search”内容?

我试图在search结果页面上获取Google的“用户也search”内容,并使用PhantomJS来刮取search结果。 但是,我所需要的知识库部分并没有出现在我所得到的body 。 有谁知道我能做些什么来让我看到?

代码如下:

 var phantom = require('phantom'); phantom.create(function (ph) { ph.createPage(function (page) { page.open("http://www.google.com/ncr", function (status) { console.log("opened google NCR ", status); page.evaluate(function () { return document.title; }, function (result) { console.log('Page title is ' + result); page.open("https://www.google.com/search?gws_rd=ssl&site=&source=hp&q=google&oq=google", function (status) { console.log("opened google Search Results ", status); page.evaluate(function () { return document.body; }, function (result) { console.log(result); ph.exit(); }); }); }); }); }); }); 

PS我必须先要求google.com/ncr强制加载Google.Com的search结果,因为我在德国,而德语版没有知识图。 也许上面的请求也可以简化…

这可能是页面的js没有完成你的身体。 尝试添加到您的page.evaluate。

 window.setTimeout( function() { <your page logic> }, 1000); 

你可能需要捣鼓的时间。

你也可以使用jquery做page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function(){<your logic>}); 打开页面之后,但运行评估之前。

find答案 – 必须手动将userAgent设置为Chrome东西

修改后的代码

 var phantom = require('phantom'); phantom.create(function (ph) { ph.createPage(function (page) { page.set('settings.userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1'); page.open("http://www.google.com/ncr", function (status) { console.log("opened google NCR ", status); page.evaluate(function () { return document.title; }, function (result) { console.log('Page title is ' + result); page.open("https://www.google.com/search?gws_rd=ssl&site=&source=hp&q=google&oq=google", function (status) { console.log("opened google Search Results ", status); page.evaluate(function () { return document.body; }, function (result) { console.log(result); ph.exit(); }); }); }); }); }); });