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}"
=begin
rate = book.xpath('//span[@class="rating_nums"]')
rate_pl = book.xpath('//span[@class="pl"]')
puts "rate #{rate}"
puts ""
=end
end
end
end
|