为了账号安全,请及时绑定邮箱和手机立即绑定

如何以编程方式搜索Google

如何以编程方式搜索Google

慕的地6264312 2019-08-03 14:03:20
如何以编程方式搜索Google有谁知道是否以及如何通过编程方式搜索Google-尤其是如果有JavaAPI的话?
查看完整描述

3 回答

?
三国纷争

TA贡献1804条经验 获得超7个赞

谷歌服务条款我们可以读到:

5.3您同意不通过Google提供的界面以外的任何其他方式访问(或试图访问)任何服务,除非在与Google的单独协议中特别允许您这样做。您特别同意不通过任何自动方式(包括使用脚本或Web爬虫)访问(或试图访问)任何服务,并应确保您遵守服务上任何robots.txt文件中的说明。

所以我想答案是否定的。更多SOAPAPI不再可用


查看完整回答
反对 回复 2019-08-05
?
翻翻过去那场雪

TA贡献2065条经验 获得超14个赞

要使用api搜索google,您应该使用Google自定义搜索,抓取网页是不允许

在java中,您可以使用CustomSearchAPI客户端Java库

maven依赖项是:

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-customsearch</artifactId>
    <version>v1-rev57-1.23.0</version></dependency>

使用GoogleCustomSearchAPI客户端库进行示例代码搜索

public static void main(String[] args) throws GeneralSecurityException, IOException {

    String searchQuery = "test"; //The query to search
    String cx = "002845322276752338984:vxqzfa86nqc"; //Your search engine

    //Instance Customsearch
    Customsearch cs = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null) 
                   .setApplicationName("MyApplication") 
                   .setGoogleClientRequestInitializer(new CustomsearchRequestInitializer("your api key")) 
                   .build();

    //Set search parameter
    Customsearch.Cse.List list = cs.cse().list(searchQuery).setCx(cx); 

    //Execute search
    Search result = list.execute();
    if (result.getItems()!=null){
        for (Result ri : result.getItems()) {
            //Get title, link, body etc. from search
            System.out.println(ri.getTitle() + ", " + ri.getLink());
        }
    }}

如你所见,你需要请求API密钥设置自己的搜索引擎id,cx.

请注意,在设置CX期间,您可以通过在基本选项卡设置上选择“搜索整个网站”来搜索整个网站,但是结果将与普通浏览器Google搜索不完全相同。

目前(答案的日期),你每天得到100个API调用免费,然后谷歌喜欢分享你的利润。




查看完整回答
反对 回复 2019-08-05
  • 3 回答
  • 0 关注
  • 313 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号