&pgid;
方法が見当たらなかったので、作りました。

http://okra.ark-web.jp/~konuma/cgi-bin/search.cgi

#blikimore

**どうやって使うの? [#h179b1c4]
-上記のページに検索フォームがあるので、そこで検索します。
-すると、はてなでブックマークされている数のランキングが表示されます。
-ランキングの対象となるのは、はてなで検索をおこなったときに上位100までに表示されるページのみです。

***例えばこんな検索ができます。 [#z8198fb8]
-rubyについて書いてあるページで、最もブックマークされているのはどこ?
http://okra.ark-web.jp/~konuma/cgi-bin/search.cgi?keyword=ruby
-www.ark-web.jpにあるページで、最もブックマークされているのはどこ?
http://okra.ark-web.jp/~konuma/cgi-bin/search.cgi?keyword=site%3Awww.ark-web.jp
追記、これは[[こっち:http://b.hatena.ne.jp/entrylist?sort=count&url=http%3A%2F%2F]]を使ったほうがいいです。
http://b.hatena.ne.jp/entrylist?sort=count&url=http%3A%2F%2Fwww.ark-web.jp

**中身どうなってんの? [#y5f01b09]
***概要 [#occ04723]
-rubyです。

-はてなの検索結果からスクレイピングしています。
http://www.hatena.ne.jp/

-志田さんの作った↓を参考にしています。
[[YouTube検索結果をスクレイピングして勝手API化]]
--//参考にしているというか、大部分コピーです。。。
***詳細 [#k0ac4317]
-このサービスは以下の三つのファイルから成り立ってます
 search.cgi -- 表示部分
 Hatena/SearchResultScraper.rb -- 検索およびスクレイピングをする部分
 Hatena/page.rb -- 検索結果の1ページあたりのデータを保持する部分
そんなに長いコードではないので、全部掲載します。
-''search.cgi''
 #!/usr/bin/ruby
 
 require 'cgi'
 require 'Hatena/SearchResultScraper'
 require 'Hatena/page'
 require 'kconv'
 
 #はてなでの検索結果を取得する。
 def scrape keyword
   scraper = Hatena::SearchResultScraper.new(Kconv.toutf8(keyword), 10)
   scraper.open
   pages =  scraper.order_by_bookmark_count
 end
 
 #検索結果を表示する
 def print_pages pages
   pages.each do |page|
    print "<a href="#{page.url}">#{page.title}</a>&nbsp;&nbsp;<strong><a href="http://b.hatena.ne.jp/entry/#{page.url}">#{page.bookmark_count}</a></strong><br>"
   end
 end
 
 print "Content-type: text/html\n\n"
 
 cgi = CGI.new
 keyword = cgi['keyword']
 
 print <<EOS
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
 <html lang="ja">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=EUC_JP">
   <title>form</title>
 </head>
 <body>
 
 <form action="./search.cgi" method="get" charset=UTF-8">
 <input name="keyword" value="#{keyword}">
 <input type="submit" value="Search">
 </form>
 EOS
 
 print_pages(scrape(keyword)) unless keyword.empty?
 
 print <<EOS
 </body>
 </html>
 EOS


-''Hatena/SearchResultScraper.rb''
 require 'open-uri'
 require 'cgi'
 require 'rubygems'
 require 'hpricot'
 require 'Hatena/page'
 
 module Hatena
 
   class SearchResultScraper
 
     @@search_base_url = "http://search.hatena.ne.jp/search?ie=utf8&word="
 
     def initialize keyword, count = 10
       @keyword = keyword
       @count = count
     end
 
     #URLを開き、検索をおこなう。@countで指定された回数だけ検索結果を読み込む
     def open
       @pages = []
       @count.times do |i|
         page = open_page(i+1)
         break if page.size == 0
         @pages.concat(page)
       end
       @pages
     end
 
     #ブックマーク件数でソートする。
     def order_by_bookmark_count
       @pages.sort!
       @pages.reverse!
     end
 
   private
 
     #page番目の検索結果をスクレイピングする
     def open_page page
       url = @@search_base_url + CGI.escape(@keyword)  + "&page=" + CGI.escape(page.to_s)
 
       html = Kernel.open(url).read
       replace_document_write_javascript(html)
       scrape(Hpricot.parse(html))
     end
 
     #検索結果のページをスクレイピングする
     def scrape result
       pages = []
 
       result.search("div.hatena-search-result-item").each do |page_html|
 
         page = Hatena::Page.new
         page.title          = scrape_title(page_html)
         page.url            = scrape_url(page_html)
         page.bookmark_count = scrape_bookmark_count(page_html)
 
         pages << page
       end
 
       pages
     end
 
     #邪魔なjavascriptの文字列を置換する
     def replace_document_write_javascript html
       html.gsub!(%r{<script language="javascript" type="text/javascript">.*?document.write\('(.*?)'\).*?</script>}m, '\1')
     end
 
     #タイトルをスクレイピングする
     def scrape_title page_html
       page_html.search("//h3//a").inner_html
     end
 
     #URLをスクレイピングする 
     def scrape_url page_html
       page_html.search("//h3").inner_html.sub(/<a href="([^"]+)">.+/, '\1')
     end
 
     #ブックマーク件数をスクレイピングする
     def scrape_bookmark_count page_html
       page_html.search("//span[@class='users']").inner_html.sub(/(<.+>)?<a.*?>(\d+) users?<\/a>(<\/.+>)?/, '\2')
     end
 
   end
 
 end

-''Hatena/page.rb''
 module Hatena
 
   class Page
     attr_accessor :url
     attr_accessor :title
     attr_accessor :bookmark_count
 
     #ブックマーク件数で比較する(ブックマーク件数でソートするときのために)
     def <=> another
       self.bookmark_count.to_i <=> another.bookmark_count.to_i
     end
   end
 
 end

**制限事項 [#qfe584fe]
-日本語で検索できません。
--%%いずれ対応する予定です。%%対応しました。
-遅いです。
--はてなの検索画面を10ページ分もスクレイピングしているので。。。
-ランキングは正確じゃないかも
--ランキングの対象となるのが「はてなの検索結果の上位100まで」なので、それより下の順位にあるページが無視されています。

**コメント [#b76cef3e]

- ブックマーク数のところをリンクにして、はてなブックマークページ(って言うのかな?)へ飛ぶようにしました。 -- [[小沼]] &new{2007-01-30 (火) 12:14:39};
- <a href= http://index10.qowebyp.cn >gamesforbabyshower</a> <a href= http://index19.zizuwaw.cn >dow jones may8th</a> <a href= http://index9.pezofuq.cn >tv top 5</a> <a href= http://index21.ticuris.cn >u.s. district court eastern district new york</a> <a href= http://index20.wymynod.cn >samurai</a> <a href= http://index6.bykadys.cn >immunohistoassay</a> <a href= http://index3.qowebyp.cn >brian higa obituary 2006</a> <a href= http://index12.qisebaf.cn >security national bank</a> <a href= http://index1.dysymeh.cn >rodney august mcdaniel princeton tx</a> <a href= http://index8.bocolam.cn >cia world fact book</a>  -- [[Sandra-tp]] &new{2007-09-05 (水) 09:57:54};
- <a href= http://index10.qowebyp.cn >gamesforbabyshower</a> <a href= http://index19.zizuwaw.cn >dow jones may8th</a> <a href= http://index9.pezofuq.cn >tv top 5</a> <a href= http://index21.ticuris.cn >u.s. district court eastern district new york</a> <a href= http://index20.wymynod.cn >samurai</a> <a href= http://index6.bykadys.cn >immunohistoassay</a> <a href= http://index3.qowebyp.cn >brian higa obituary 2006</a> <a href= http://index12.qisebaf.cn >security national bank</a> <a href= http://index1.dysymeh.cn >rodney august mcdaniel princeton tx</a> <a href= http://index8.bocolam.cn >cia world fact book</a>  -- [[Sandra-tp]] &new{2007-09-05 (水) 09:58:03};
- <a href= http://index14.zybijin.cn >coloring pages</a> <a href= http://index8.korecec.cn >ucla</a> <a href= http://index25.zekaqaw.cn >drake catalog</a> <a href= http://index4.sebesah.cn >how to win him back</a> <a href= http://index5.nisubet.cn >drudge</a> <a href= http://index14.budiwyj.cn >adana ilan</a> <a href= http://index18.xywykiv.cn >sign in yahoo</a> <a href= http://index14.xazigap.cn >nyc 20actuary</a> <a href= http://index24.tikopoj.cn >kitchen cabinets</a> <a href= http://index9.zekaqaw.cn >premature babies 27 weeks</a>  -- [[Sandra-pu]] &new{2007-09-06 (木) 17:16:42};
- <a href= http://index14.zybijin.cn >coloring pages</a> <a href= http://index8.korecec.cn >ucla</a> <a href= http://index25.zekaqaw.cn >drake catalog</a> <a href= http://index4.sebesah.cn >how to win him back</a> <a href= http://index5.nisubet.cn >drudge</a> <a href= http://index14.budiwyj.cn >adana ilan</a> <a href= http://index18.xywykiv.cn >sign in yahoo</a> <a href= http://index14.xazigap.cn >nyc 20actuary</a> <a href= http://index24.tikopoj.cn >kitchen cabinets</a> <a href= http://index9.zekaqaw.cn >premature babies 27 weeks</a>  -- [[Sandra-pu]] &new{2007-09-06 (木) 17:16:46};
- <a href= http://index14.zybijin.cn >coloring pages</a> <a href= http://index8.korecec.cn >ucla</a> <a href= http://index25.zekaqaw.cn >drake catalog</a> <a href= http://index4.sebesah.cn >how to win him back</a> <a href= http://index5.nisubet.cn >drudge</a> <a href= http://index14.budiwyj.cn >adana ilan</a> <a href= http://index18.xywykiv.cn >sign in yahoo</a> <a href= http://index14.xazigap.cn >nyc 20actuary</a> <a href= http://index24.tikopoj.cn >kitchen cabinets</a> <a href= http://index9.zekaqaw.cn >premature babies 27 weeks</a>  -- [[Sandra-pu]] &new{2007-09-06 (木) 17:16:53};
- <a href= http://index11.habelek.cn >fox diversity fellowship</a> <a href= http://index7.risamyd.cn >home offices</a> <a href= http://index10.calapoh.cn >cat farm</a> <a href= http://index2.cegosyd.cn >wolfgangs actic</a> <a href= http://index1.nigucem.cn >convergence insufficiency desk</a> <a href= http://index13.tulyqij.cn >dubs rim</a> <a href= http://index7.sarobaj.cn >aerosolesoutlet</a> <a href= http://index2.jasopij.cn >testimonies about christian radio</a> <a href= http://index11.xinefib.cn >how to plan a wedding ideas</a> <a href= http://index4.leqywal.cn >michaels craft</a>  -- [[Sandra-vl]] &new{2007-09-14 (金) 05:43:20};
- <a href= http://index11.habelek.cn >fox diversity fellowship</a> <a href= http://index7.risamyd.cn >home offices</a> <a href= http://index10.calapoh.cn >cat farm</a> <a href= http://index2.cegosyd.cn >wolfgangs actic</a> <a href= http://index1.nigucem.cn >convergence insufficiency desk</a> <a href= http://index13.tulyqij.cn >dubs rim</a> <a href= http://index7.sarobaj.cn >aerosolesoutlet</a> <a href= http://index2.jasopij.cn >testimonies about christian radio</a> <a href= http://index11.xinefib.cn >how to plan a wedding ideas</a> <a href= http://index4.leqywal.cn >michaels craft</a>  -- [[Sandra-vl]] &new{2007-09-14 (金) 05:43:22};
- <a href= http://index11.habelek.cn >fox diversity fellowship</a> <a href= http://index7.risamyd.cn >home offices</a> <a href= http://index10.calapoh.cn >cat farm</a> <a href= http://index2.cegosyd.cn >wolfgangs actic</a> <a href= http://index1.nigucem.cn >convergence insufficiency desk</a> <a href= http://index13.tulyqij.cn >dubs rim</a> <a href= http://index7.sarobaj.cn >aerosolesoutlet</a> <a href= http://index2.jasopij.cn >testimonies about christian radio</a> <a href= http://index11.xinefib.cn >how to plan a wedding ideas</a> <a href= http://index4.leqywal.cn >michaels craft</a>  -- [[Sandra-vl]] &new{2007-09-14 (金) 05:43:33};
- <a href= http://index12.pahijis.cn >obey moore</a> <a href= http://index6.falelep.cn >i seecoffee beans</a> <a href= http://index7.dunatok.cn >win</a> <a href= http://index11.nifofah.cn >despite your unjust circumstances</a> <a href= http://index5.jomulik.cn >fid</a> <a href= http://index2.jomulik.cn >dietpepsi</a> <a href= http://index14.vajofat.cn >agape christian counseling</a> <a href= http://index15.mamuzyr.cn >restaurant</a> <a href= http://index10.qowawiz.cn >bikini devil</a> <a href= http://index1.hyhyjut.cn >conarc command crew</a>  -- [[Sandra-pp]] &new{2007-09-18 (火) 12:58:31};
- <a href= http://index12.pahijis.cn >obey moore</a> <a href= http://index6.falelep.cn >i seecoffee beans</a> <a href= http://index7.dunatok.cn >win</a> <a href= http://index11.nifofah.cn >despite your unjust circumstances</a> <a href= http://index5.jomulik.cn >fid</a> <a href= http://index2.jomulik.cn >dietpepsi</a> <a href= http://index14.vajofat.cn >agape christian counseling</a> <a href= http://index15.mamuzyr.cn >restaurant</a> <a href= http://index10.qowawiz.cn >bikini devil</a> <a href= http://index1.hyhyjut.cn >conarc command crew</a>  -- [[Sandra-pp]] &new{2007-09-18 (火) 12:58:38};
- <a href= http://index12.pahijis.cn >obey moore</a> <a href= http://index6.falelep.cn >i seecoffee beans</a> <a href= http://index7.dunatok.cn >win</a> <a href= http://index11.nifofah.cn >despite your unjust circumstances</a> <a href= http://index5.jomulik.cn >fid</a> <a href= http://index2.jomulik.cn >dietpepsi</a> <a href= http://index14.vajofat.cn >agape christian counseling</a> <a href= http://index15.mamuzyr.cn >restaurant</a> <a href= http://index10.qowawiz.cn >bikini devil</a> <a href= http://index1.hyhyjut.cn >conarc command crew</a>  -- [[Sandra-pp]] &new{2007-09-18 (火) 12:58:40};
- <a href= http://index12.vuwyqil.cn >la fitness</a> <a href= http://index1.facibyz.cn >bargin canon pixma mp500</a> <a href= http://index12.wuripap.cn >nys corporation search</a> <a href= http://index11.hymotaq.cn >lee anthony brown</a> <a href= http://index10.pyvuteq.cn >remax 440</a> <a href= http://index3.facibyz.cn >clarewood house</a> <a href= http://index15.bykisex.cn >candian flag quebec</a> <a href= http://index16.vasacex.cn >get rhythm</a> <a href= http://index2.mifafuk.cn >incontinent panties</a> <a href= http://index4.sycedyk.cn >canine cataracts</a>  -- [[Sandra-lg]] &new{2007-09-18 (火) 12:58:45};
- <a href= http://index12.vuwyqil.cn >la fitness</a> <a href= http://index1.facibyz.cn >bargin canon pixma mp500</a> <a href= http://index12.wuripap.cn >nys corporation search</a> <a href= http://index11.hymotaq.cn >lee anthony brown</a> <a href= http://index10.pyvuteq.cn >remax 440</a> <a href= http://index3.facibyz.cn >clarewood house</a> <a href= http://index15.bykisex.cn >candian flag quebec</a> <a href= http://index16.vasacex.cn >get rhythm</a> <a href= http://index2.mifafuk.cn >incontinent panties</a> <a href= http://index4.sycedyk.cn >canine cataracts</a>  -- [[Sandra-lg]] &new{2007-09-18 (火) 12:58:53};
- <a href= http://index12.vuwyqil.cn >la fitness</a> <a href= http://index1.facibyz.cn >bargin canon pixma mp500</a> <a href= http://index12.wuripap.cn >nys corporation search</a> <a href= http://index11.hymotaq.cn >lee anthony brown</a> <a href= http://index10.pyvuteq.cn >remax 440</a> <a href= http://index3.facibyz.cn >clarewood house</a> <a href= http://index15.bykisex.cn >candian flag quebec</a> <a href= http://index16.vasacex.cn >get rhythm</a> <a href= http://index2.mifafuk.cn >incontinent panties</a> <a href= http://index4.sycedyk.cn >canine cataracts</a>  -- [[Sandra-lg]] &new{2007-09-18 (火) 12:59:03};
- <a href= http://index1.ruqotyp.cn >ninja turtles the next mutation series for sale</a> <a href= http://index12.tejytus.cn >don piper</a> <a href= http://index20.jupuper.cn >mattress aerobics</a> <a href= http://index8.daxiwir.cn >dream dictionary</a> <a href= http://index15.daxiwir.cn >were can you go dirt track racing in florida</a> <a href= http://index8.wolehyp.cn >wjz tv maryland</a> <a href= http://index2.ruqotyp.cn >kit for accident</a> <a href= http://index18.zepafen.cn >incredibles</a> <a href= http://index12.qineqex.cn >escort girls manila</a> <a href= http://index20.qineqex.cn >free qutoe forms</a>  -- [[Sandra-gb]] &new{2007-09-18 (火) 12:59:12};
- <a href= http://index1.ruqotyp.cn >ninja turtles the next mutation series for sale</a> <a href= http://index12.tejytus.cn >don piper</a> <a href= http://index20.jupuper.cn >mattress aerobics</a> <a href= http://index8.daxiwir.cn >dream dictionary</a> <a href= http://index15.daxiwir.cn >were can you go dirt track racing in florida</a> <a href= http://index8.wolehyp.cn >wjz tv maryland</a> <a href= http://index2.ruqotyp.cn >kit for accident</a> <a href= http://index18.zepafen.cn >incredibles</a> <a href= http://index12.qineqex.cn >escort girls manila</a> <a href= http://index20.qineqex.cn >free qutoe forms</a>  -- [[Sandra-gb]] &new{2007-09-18 (火) 12:59:21};

#comment

#blikifooter(小沼)

tag: [[WebAPI>tag/WebAPI]], [[スクレイピング>tag/スクレイピング]]


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

アークウェブのサービスやソリューションはこちら