r2 - 09 Sep 2008 - 15:37:43 - Main.yfangYou are here: YWiki >  MyTech Web > YahooBoss实战

Yahooboss

Yahooboss 简介

  • 这是一个Yahoo最近开放的搜索API,官方网站:http://developer.yahoo.com/search/boss/,它可以让你根据简单的需求定制查询,直接以json或是xml的形式获得yahoo搜索返回的结果,根据Boss的声明,你可以对得到的数据进行重排,处理,插入,删除等操作,甚至你可以处理数据融合你的私有数据,定制成独一无二的高级服务,是不是很有诱惑。更爽的是,不仅免费,而且每天不限次数的调用。有兴趣的话来试试吧!

Yahooboss 体验过程

  • 0. 作为开发的准备工作,你必须要拥有一个可以控制的域名,把它指向一个ip,开启一个简单的web服务,我用的是自己的boss.yfang.cn。出于好心,我强烈建议你看看Boss手册,虽然内容不多,但是里面说明了我接下来做的几乎所有事情。
  • 1. 首先你需要有一个Yahoo! ID,这个东西很简单,通常就是你的yahoo邮箱xxx@yahoo.com[.cn]中间的xxx部分。首先登录你的id。
  • 2. 访问http://developer.yahoo.com/wsregapp/申请你的应用,仔细填写表格,关于应用的位置并不需要详细填写,只要把你自己的网站地址,比如http://boss.yfang.cn/填写正确就可以了,最后一项,一定要选上“BOSS Search Service”,其他没有什么问题了,继续 yboss1.jpg
  • 3. 这时你应该看到了一个象下面这样的验证页面,按他说的在你的web根目录创建这样一个文件,并且包含他写的那些信息,点击“Check Domain”,如果你操作没有问题这里就通过了,得到一句“Result: Pass (checked http://boss.yfang.cn/ydnR5qRUl.html). You can remove this file now. ”。继续 yboss2.jpg
  • 4. 这样你得到了最重要的一个application id,把他记下来,后面要用 yboss3.jpg

  • 5. 从这一步开始是程序员的事情了,你可以选用自己喜欢的web开发语言和工具。这里我只想简单说一下思路,编程语言相关的内容一概忽略
    • 明确一点,你需要在你的代码中写一部分从yahoo获取数据的代码,实际上就是从一个URL获得需要的数据,这个URL通常包含搜索的类型(可能包括网页,图片,新闻等),搜索关键字,你的application id(前面获得的),结果格式,条目开始值(这个相当于偏移量),取多少条记录,还有一些特定的参数。
    • 一个网页搜索的标准URL类似于:http://boss.yahooapis.com/ysearch/web/v1/{query}?appid=yourappid[&param1=val1&param2=val2&etc]
    • 一个图片搜索的标准URL类似于:http://boss.yahooapis.com/ysearch/images/v1/{query}?appid=yourappid[&param1=val1&param2=val2&etc]
    • 一个新闻搜索的标准URL类似于:http://boss.yahooapis.com/ysearch/news/v1/{query}?appid=yourappid[&param1=val1&param2=val2&etc]
    • 你的程序去访问相应的URL后会得到相应的数据,用xml模块或者json的模块处理一下便可以轻松得到你需要的数据了。 * 接下来你只需要根据需要组织输出即可。

  • 典型的网页搜索XML格式结果
<ysearchresponse responsecode="200">
  <nextpage>/ysearch/web/v1/foo?format=xml&start=10&count=10</nextpage>
  <resultset_web count="10" start="0" totalhits="29440998" deephits="881000000">
    <result>
      <abstract><![CDATA[World <b>soccer</b> coverage
                from ESPN, including Premiership, Serie A, La Liga, and Major League
                <b>Soccer</b>. Get news headlines, live scores, stats, and
                tournament information.]]></abstract>
      <date>2008/06/08</date>
      <dispurl><![CDATA[www.<b>soccernet.com</b>]]></dispurl>
      <clickurl>http://us.lrd.yahoo.com/_ylc=X3oDMTFkNXVldGJyBGFwcGlkA2Jvc3NkZW1vBHBvcwMwBHNlcnZpY2UDWVNlYXJjaARzcmNwdmlkAw--
                /SIG=10u3e8260/**http%3A//www.soccernet.com/</clickurl>
      <size>94650</size>
      <title>ESPN Soccernet</title>
      <url>http://www.soccernet.com/</url>
    </result>
  </resultset_web>
</ysearchresponse>

  • 典型的图片搜索XML格式结果
<ysearchresponse responsecode="200">
  <nextpage>/ysearch/images/v1/soccer?format=xml&start=10&count=10</nextpage>
  <resultset_images count="10" start="0" totalhits="4195016" deephits="4195016">
    <result>
    <abstract>Now we don't know Crawford from Adam but he's a good friend of WCP-occasional-contributor Beans and he 
              somewhat has a point, or at least made us laugh while making it.
    </abstract>
    <clickurl>http://us.lrd.yahoo.com/_ylc=X3oDMTFkNXVldGJyBGFwcGlkA2Jvc3NkZW1vBHBvcwMwBHNlcnZpY2UDWVNlYXJjaARzcmNwdmlkAw
              --/SIG=12f47a1hh/**http%3A//wickedchopspoker.blogs.com/my_weblog/images/why_men_love_soccer.jpg</clickurl>
    <filename>why_men_love_soccer.jpg</filename>
    <size>31500</size>
    <format>jpeg</format>
    <height>213</height>
    <date>2006/06/09</date>
    <mimetype>image/jpeg</mimetype>
    <refererclickurl>http://wickedchopspoker.blogs.com/my_weblog/2006/06/world_cup_musin.html</refererclickurl>
    <refererurl>http://wickedchopspoker.blogs.com/my_weblog/2006/06/world_cup_musin.html</refererurl>
    <title>why_men_love_soccer.jpg</title>
    <url>http://wickedchopspoker.blogs.com/my_weblog/images/why_men_love_soccer.jpg</url>
    <width>230</width>
    <thumbnail_height>120</thumbnail_height>
    <thumbnail_url>http://re3.yt-thm-a01.yimg.com/image/25/m7/3979077535</thumbnail_url>
    <thumbnail_width>130</thumbnail_width>
    </result>
  </resultset_images>
</ysearchresponse>

  • 典型新闻搜索XML格式结果
<ysearchresponse responsecode="200">
  <nextpage>/ysearch/news/v1/soccer?format=xml&start=10&count=10</nextpage>
  <resultset_news count="10" start="0" totalhits="8775"deephits="8775">
    <result>
      <abstract>June 16 (Bloomberg) -- Adidas AG , the world's second - largest sporting-goods maker, will ``clearly exceed'' its full-
        year sales target for soccer-related goods and gain share in all major markets, Chief Executive Officer Herbert Hainer
        said.
      </abstract>
      <clickurl>http://www.bloomberg.com/apps/news?pid=20601100&sid=aSSf0jMZtvBU</clickurl>
      <title>Adidas Will `Clearly Exceed' Soccer Sales Target, Hainer Says</title>
      <language>en english</language>
      <date>2008/06/16</date>
      <time>14:21:15</time>
      <source>Bloomberg.com</source>
      <sourceurl>http://www.bloomberg.com/</sourceurl>
      <url>http://www.bloomberg.com/apps/news?pid=20601100&sid=aSSf0jMZtvBU</url>
    </result>
  </resultset_news>
</ysearchresponse>

  • 关于默认值的说明:(这里只是简单列举一些最重要的,还有很多特定参数参看手册)
start 0 WEB/NEWS/IMAGES 表明搜索偏移量,制作翻页时用得到
count 10 WEB/NEWS/IMAGES 表明返回的结果数量(当然前提是有这么多的数据)
age 7d NEWS 表明从什么时候开始的新闻有效,默认7天,可选1天到30天

存在的问题

  • 部分搜索有bug,这个API在某些情况下会返回空,导致某些页面没有数据,感觉应该是Boss的bug,不过这个随着时间变化不确定,不容易简单重现。
  • 同样的检索条件下,page和count设置不同导致数据完全不一致,有些困惑。比如count设成20看到的第5页应该和count设成10看到的第9第10页内容一样,实际上不太一样,其实即便同样条件,连续查询两次总结果数量都会不同,不是什么严重问题。
  • 由于API的限制,中文的搜索不是很好,具体说明参见。。。

多说两句

  • 其实如果光是简单的API使用的话,没什么意思,最好是借助这个API和你私有的数据,才能创造出独一无二的有意义的站点来

参考资料

Topic attachments
I Attachment Action Size Date Who Comment
jpgjpg yboss1.jpg manage 75.3 K 09 Sep 2008 - 15:23 Main.yfang  
jpgjpg yboss2.jpg manage 41.7 K 09 Sep 2008 - 15:25 Main.yfang  
jpgjpg yboss3.jpg manage 24.1 K 09 Sep 2008 - 15:26 Main.yfang  
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by YWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding YWiki? Send feedback