# File lib/nicovideo/search.rb, line 7 def initialize agent, keyword, sort=nil, order=nil, pagenum=1 super(agent) @search_type = 'search' #@keyword = CGI.escape(CGI.escape(keyword)) @keyword = CGI.escape(keyword) @sort = sort @order = order @pagenum = pagenum params = ["videos", "total_size", "has_next?", "has_prev?"] self.register_getter params @url = url() puts_info "url = #{@url}" puts_info "sort=#{@sort},order=#{@order},pagenum=#{@pagenum}" end
# File lib/nicovideo/search.rb, line 34 def each self.videos.each {|v| yield v } end
# File lib/nicovideo/search.rb, line 54 def next self.pagenum = @pagenum + 1 self end
# File lib/nicovideo/search.rb, line 50 def page=(pagenum) self.pagenum = pagenum end
# File lib/nicovideo/search.rb, line 42 def pagenum=(pagenum) if @pagenum != pagenum @pagenum = pagenum get_page(self.url, true) end @pagenum end
# File lib/nicovideo/search.rb, line 65 def parse(page) if page.body =~ /<\/strong> を含む動画はありません。/ @not_found = true raise NotFound end @total_size = page.search('strong[@class="search_total"]').first.inner_html.sub(/,/,'').to_i @has_next = false @has_prev = false respages = page/'//div[@class="pagelink"]' puts_info respages.size respages.each {|r| puts_info r.inner_html } if respages.size > 0 respages.each {|text| if text.inner_html =~ /<a class="prevpage".*?>.*?戻る.*?<\/a>/ @has_prev = true end if text.inner_html =~ /<a class="nextpage".*?>.*?進む.*?<\/a>/ @has_next = true end } end result_xpath = page/'//div[@class="cmn_thumb_R"]//p[@class="TXT12"]/a[@class="video"]' puts_info result_xpath.size.to_s @videos = result_xpath.inject([]) {|arr, v| vp = VideoPage.new(@agent, v.attributes['href'].sub(/watch\/(\w+)$/,'\1')) vp.title = v.inner_html arr << vp } end
Generated with the Darkfish Rdoc Generator 2.