Module: Douban

Defined in:
lib/my_utils/douban.rb

Class Method Summary collapse

Class Method Details

.get_book(title) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/my_utils/douban.rb', line 6

def self.get_book title
	target = URI.encode("http://book.douban.com/subject_search?search_text=#{title}")
	open(target) do |http|
		doc = Nokogiri::HTML(http.read)
		book_list = doc.xpath('//li[@class="subject-item"]')
		book_list.each_with_index do |bk, idx|
			rate = bk.xpath('//div/span[@class="rating_nums"]')
			puts "rate: #{rate}"
			#puts "item #{idx}: #{book}"
			#puts "\n"
=begin
			rate = book.xpath('//span[@class="rating_nums"]')
			rate_pl = book.xpath('//span[@class="pl"]')

			puts "rate #{rate}"
			puts ""
=end

			#puts "rate_pl #{rate_pl.content}"
		end
		#puts http.read
	end
end