如何使Google的知识图“人们也在搜索"内容? [英] How to get Google's Knowledge Graph "people also search for" content?

查看:77
本文介绍了如何使Google的知识图“人们也在搜索"内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在搜索结果页面上获取Google的用户也在搜索"内容,而我正在使用PhantomJS抓取其结果.但是,我需要的知识库部分未显示在我得到的body中.有人知道我能做什么显示给我吗?

I'm trying to get Google's "People also search for" content on the search results page and I'm using PhantomJS to scrape their results. However, that Knowledgebase part I need does not show up in the body I get. Does anyone know what I could do to have it shown to me?

代码如下:

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的结果,因为我位于德国,而德语版本没有知识图.也许上面的请求也可以简化...

PS I have to first request `google.com/ncr' to force-load Google.Com's results as I'm based in Germany and the German version does not have the knowledge graph. Maybe the requests above can also be simplified...

推荐答案

可能是到您获取正文时页面的js尚未完成.尝试将其添加到您的page.evaluate.

It may be that the page's js hasn't finished by the time you get the body. Try adding this into your page.evaluate.

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

您可能需要摆弄时间.

You may need to fiddle with the time.

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

Also you can use jquery by doing page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function(){<your logic>}); after opening the page but before running the evaluate.

这篇关于如何使Google的知识图“人们也在搜索"内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆