(PHP)如何解析Google搜索结果中的URL? [英] (PHP) How to parse URLs in google search results?

查看:180
本文介绍了(PHP)如何解析Google搜索结果中的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Google搜索结果的网址?

How get google search results url?

(我使用Zend_Gdata_Gbase来获取搜索的Google结果,而不是DomDocument/htmlsimpleparser,因为在我看来Zend_Gdata_Gbase专门用于解析Google结果. 如果我的选择有误,请写信.)

(I use Zend_Gdata_Gbase for get search google results and not DomDocument/htmlsimpleparser because its looks to me that Zend_Gdata_Gbase done specially for parsing google results. if I wrong in my selection, please write.)

我获取"yahoo"或其他查询搜索字符串的Google搜索结果的功能: (该函数获得的提要应该具有单词"yahoo"的搜索结果,但是当我使用prin_t($ feed)时,我看不到每个结果的网址)

My function to get google search results for 'yahoo' or other query search string: (the function get a feed that should have search result for word 'yahoo', but when i use prin_t($feed) I don't see url for each result)

<?php    
function queryGoogleSearch($queryString='yahoo'){
            $service = new Zend_Gdata_Gbase();
            $query = $service->newSnippetQuery();
            $query->setBq('['.$queryString.']');
            $query->setOrderBy('modification_time');
            $query->setSortOrder('descending');
            $query->setMaxResults('4');
            $feed = $service->getGbaseSnippetFeed($query);
            return $feed; 
    }
    print_r(queryGoogleSearch());
?>

我得到4个第一个url结果(当我在google中手动搜索时):

I get 4 first url results (when I search manually in google):

www.yahoo.com,mail.yahoo.com,search.yahoo.com,maps.yahoo.com

www.yahoo.com, mail.yahoo.com, search.yahoo.com, maps.yahoo.com

但是当我打印$ feed变量时找不到它们.

But I can't find them when I print $feed variable.

请问我应该更改或添加inqueryGoogleSearch()函数吗? (或其他更好的代码)

Please what should i change or add inqueryGoogleSearch() function? (Or other better code)

谢谢

推荐答案

您是否要搜索google.com.看起来该类适用于Google Base,而不适用于google.com搜索引擎. http://base.google.com/support/bin/answer.py? hl = zh-CN& answer = 59260

Are you trying to search google.com. Looks like that class is for Google Base, not google.com search engine. http://base.google.com/support/bin/answer.py?hl=en&answer=59260

您可能想要这样: http://code.google.com/apis/customsearch/v1/overview.html 他们最近才改变了这一点.从11月1日起,旧的Google搜索API已弃用.自定义搜索是新的API.

You probably want this: http://code.google.com/apis/customsearch/v1/overview.html They recently just changed this. The old google search API has now deprecated as of Nov 1st. Custom search is the new API.

在没有Zend的情况下使用起来非常简单.

Its pretty simple to use without Zend.

http://code.google.com/apis/customsearch/v1/using_rest.html #WorkingResults

PHP中有一个JSON解码器. http://php.net/manual/en/function.json-decode.php

There is a JSON decoder in PHP. http://php.net/manual/en/function.json-decode.php

希望有帮助!

这篇关于(PHP)如何解析Google搜索结果中的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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