简体   繁体   English

NodeJS - Google 搜索 API 没有返回任何内容

[英]NodeJS - Google search API isn't returning anything

I'm using NodeJS and I'm trying to perform a Google search.我正在使用 NodeJS,并且正在尝试执行 Google 搜索。

I'm using the google package .我正在使用谷歌 package Here is my code:这是我的代码:

const google = require('google');
google.resultsPerPage = 25;

        google('wikipedia', function (err, res) {
            if (err) console.log(err);
        });
            console.log(res.links);
        });

And res.links is an empty array. res.links是一个空数组。 I made the search manually, with the exact link used by the node app (which is https://www.google.com/search?hl=en&q=wikipedia&start=0&sa=N&num=25&ie=UTF-8&oe=UTF-8&gws_rd=ssl ), and I get results.我手动进行了搜索,使用节点应用程序使用的确切链接(即https://www.google.com/search?hl=en&q=wikipedia&start=0&sa=N&num=25&ie=UTF-8&oe=UTF-8&gws_rd= ssl ),我得到了结果。

Do you have any idea why it's not returning anything?你知道为什么它没有返回任何东西吗?

First You have a syntax error首先你有一个语法错误

It should be它应该是

const google = require('google');

google.resultsPerPage = 25;

google('wikipedia', function (err, res) {
    if (err) console.log(err);
    else {
        console.log(res.links);
    }
});

Second, if you check the package's Github page, it seems that the it does not work anymore https://github.com/jprichardson/node-google/issues/65 and they are suggesting using https://www.npmjs.com/package/google-it instead.其次,如果您检查包的 Github 页面,它似乎不再起作用 https://github.com/jprichardson/node-google/issues/65并且他们建议使用Z5E056C500A50D1C4B6A7Z1 /package/google-it代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM