daodao 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94e13e69f1a94e9ef2457e87b79d059580e4e62b
4
- data.tar.gz: b6ff9806987c8b4b28ac3fdbb8802c4728676165
3
+ metadata.gz: 9b7e9eacbf6cbe5bbfc30e566447703171f97c88
4
+ data.tar.gz: 6b3d10c511674c81b83d3776fb7d894540a823f2
5
5
  SHA512:
6
- metadata.gz: 76c7b442362b441f4a038bccf9bb74a4eadcc802692c37049200f2e870f187caffafed1afea874bf05b4228976cc9da6923f1e277da39b8e10f1c495fd498a28
7
- data.tar.gz: 1e302326ab4b61b556dad26e114055f29e3d3f067bfc7dba09a8adb6e6cdb9eb11e4e81149058587a2f795dec4d44451323fbd03266ef12ab1d44cba50e65dc4
6
+ metadata.gz: 016d318b1aa5093632ed066c32b92c0d1fe85d863daaece9451fe5b136f0f285f94c3dfa1bee99a03f1d7c7ff2d96076c5dc29a313ba0823a56cbd97f1a7db93
7
+ data.tar.gz: f9d53f41a5ed4f21e4961c0f2537aefd8da3fe169807c3e9ff05bf77ed2c8facb0e6541c424cbfbb74258206a1628a072d3805862b4f15f0b8394454527f622c
data/README.md CHANGED
@@ -28,14 +28,14 @@ Or install it yourself as:
28
28
 
29
29
  ```ruby
30
30
  require 'daodao'
31
- uri = "/Hotel_Review-g298555-d2682464-Reviews-Four_Seasons_Hotel_Guangzhou-Guangzhou_Guangdong.html"
32
- sample = Daodao::Rank.new(uri)
31
+ hotel_id = "2682464"
32
+ sample = Daodao::Rank.new(hotel_id)
33
33
  puts 'The rooms details are as follow :'
34
34
  puts sample.rooms_details
35
35
  ```
36
36
  This will crawl the rooms details of the target hotel for you.
37
37
 
38
- `Note:` You can pass other uri to `initialize` representing the hotel page.
38
+ `Note:` You can pass other hotel_id to `initialize` representing the hotel page.
39
39
 
40
40
  #### Get ota's ranking
41
41
 
@@ -7,17 +7,28 @@ require 'daodao/rank'
7
7
  require 'daodao/hotel'
8
8
  require 'daodao/hotel_list'
9
9
  module Daodao
10
- def self.rank(url)
11
- page = Nokogiri::HTML(open(url))
10
+ def self.rank(hotel_id)
11
+ url = "http://www.daodao.com/Hotel_Review/d#{hotel_id}"
12
+ @html = Nokogiri::HTML(open(url))
12
13
  row = {}
13
- row[:hotel_id] = url.split('-')[2]
14
- row[:hotel_name] = page.xpath('//span[@itemprop="name"]').text
14
+ row[:hotel_id] = hotel_id[/\d+/]
15
15
  rank=1
16
- page.css("div.provider_meta_overview").each { |item|
17
- key = 'rank'+rank.to_s
18
- row[key.to_sym] = item.css("span.providerLogo_96x41").xpath('./img/@alt').first.value
19
- rank+=1
20
- }
16
+ provider = @html.css("div.no_cpu.offer or span.no_cpu.offer")
17
+ if provider.empty?
18
+ row[:hotel_name] = @html.xpath("//span[@itemprop='name']").text
19
+ @html.css("div.provider_meta_overview").each { |item|
20
+ key = 'rank'+rank.to_s
21
+ row[key.to_sym] = item.at("span[@class='providerLogo_96x41']/img")['alt']
22
+ rank+=1
23
+ }
24
+ else
25
+ row[:hotel_name] = @html.xpath("//h1[@id='HEADING']").text
26
+ provider.each { |item|
27
+ key = 'rank'+rank.to_s
28
+ row[key.to_sym] = item['data-vendorname']
29
+ rank+=1
30
+ }
31
+ end
21
32
  row
22
33
  end
23
34
  end
@@ -6,7 +6,7 @@ module Daodao
6
6
  def initialize(hotel_id)
7
7
  raise "The argument of class HotelInfo should be string" if !hotel_id.instance_of?(String)
8
8
  @id = hotel_id
9
- @url = URI("http://daodao.com/Hotel_Review-#{hotel_id}")
9
+ @url = URI("http://daodao.com/Hotel_Review-d#{hotel_id}")
10
10
  @pages = Nokogiri::HTML(open(@url))
11
11
  end
12
12
 
@@ -18,7 +18,7 @@ module Daodao
18
18
  page.xpath("//dl/a").each { |hotel|
19
19
  item = {}
20
20
  item[:name] = hotel.text
21
- item[:url] = hotel['href']
21
+ item[:id] = hotel['href'].split('-')[2][/\d+/]
22
22
  hotel_list.push(item)
23
23
  }
24
24
  return hotel_list
@@ -2,33 +2,59 @@ module Daodao
2
2
  class Rank
3
3
  include Capybara::DSL
4
4
 
5
- def initialize(uri)
6
- Capybara.current_driver = :webkit
7
-
5
+ def initialize(hotel_id)
6
+ raise ArgumentError, "initizlize: Argument should be string " if !hotel_id.instance_of?(String)
7
+ Capybara.current_driver = :webkit
8
8
  Capybara.default_selector = :xpath
9
-
10
9
  Capybara.app_host ="http://daodao.com"
10
+
11
11
  page.driver.header "User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.77.4 (KHTML, like Gecko) Version/7.0.5 Safari/537.77.4"
12
- puts " \e[34mBuilding Session...\e[0m"
13
- @uri = uri
14
- page.visit(URI(uri))
12
+ @id = hotel_id
13
+ uri = "/Hotel_Review/d#{hotel_id}"
14
+ page.visit URI(uri)
15
15
  # Click the div to navigate hidden info
16
16
  page.all("//div[@class='tab ']").each do |node|
17
17
  node.trigger('click')
18
18
  end
19
19
  # Expand all divs tagged with '展开报价'
20
- page.all("div[@class='provider_meta_overview mskQC_Meta_RoomTab msk']//*[text()='展开报价']").each do |layout|
21
- puts '展开报价...'
20
+ page.all("//span[text()='展开报价']").each do |layout|
22
21
  layout.trigger('click')
23
22
  end
24
- @page = Nokogiri::HTML(page.html)
23
+ @html = Nokogiri::HTML(page.html)
24
+ end
25
+
26
+ def id
27
+ @id
28
+ end
29
+
30
+ def rank
31
+ row = {}
32
+ row[:hotel_id] = self.id
33
+ rank=1
34
+ poi = @html.css("div.no_cpu.offer or span.no_cpu.offer")
35
+ if poi.empty?
36
+ row[:hotel_name] = @html.xpath("//span[@itemprop='name']").text
37
+ @html.css("div.provider_meta_overview").each { |item|
38
+ key = 'rank'+rank.to_s
39
+ row[key.to_sym] = item.at("span[@class='providerLogo_96x41']/img")['alt']
40
+ rank+=1
41
+ }
42
+ else
43
+ row[:hotel_name] = @html.xpath("//h1[@id='HEADING']").text
44
+ poi.each { |item|
45
+ key = 'rank'+rank.to_s
46
+ row[key.to_sym] = item['data-vendorname']
47
+ rank+=1
48
+ }
49
+ end
50
+ row
25
51
  end
26
52
 
27
53
  # Get all the rooms details
28
54
  # @Return: an array, a list of rooms details
29
55
  def rooms_details
30
56
  otas = []
31
- @page.css("div.provider_meta_overview").each { |item|
57
+ @html.css("div.provider_meta_overview").each { |item|
32
58
  row = {}
33
59
  row[:ota_name] = item.css("span.providerLogo_96x41").xpath('./img/@alt').first.value
34
60
 
@@ -42,7 +68,7 @@ module Daodao
42
68
  end
43
69
 
44
70
  rooms = []
45
- dropdown_room_list = @page.css("div.provider_rooms_details")[otas.size]
71
+ dropdown_room_list = @html.css("div.provider_rooms_details")[otas.size]
46
72
  dropdown_room_list.xpath("./a").each do |room_details|
47
73
  room = {}
48
74
  room[:room_type] = room_details.at_css("span.room_type").text
@@ -63,30 +89,13 @@ module Daodao
63
89
  return otas
64
90
  end
65
91
 
66
- def name
67
- @page.xpath('//span[@itemprop="name"]').text
68
- end
69
-
70
- def id
71
- @uri.split('-')[2]
72
- end
73
-
74
- def rank
75
- row = {}
76
- row[:hotel_id] = self.id
77
- row[:hotel_name] = self.name
78
- rank=1
79
- @page.css("div.provider_meta_overview").each { |item|
80
- key = 'rank'+rank.to_s
81
- row[key.to_sym] = item.css("span.providerLogo_96x41").xpath('./img/@alt').first.value
82
- rank+=1
83
- }
84
- return row
85
- end
86
-
87
92
  def screen_shot
88
93
  page.save_screenshot("#{Time.now}.png")
89
94
  end
90
95
 
96
+ def html
97
+ @html
98
+ end
99
+
91
100
  end
92
101
  end
@@ -1,3 +1,3 @@
1
1
  module Daodao
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Daodao::Hotel do
4
4
  # hotel in guangzhou
5
- gz_sample = Daodao::Hotel.new("d2682464")
5
+ gz_sample = Daodao::Hotel.new("2682464")
6
6
 
7
7
  it "has name '四季酒店'" do
8
8
  expect(gz_sample.name).to eq '四季酒店'
9
9
  end
10
10
 
11
11
  it "has id 'd2682464'" do
12
- expect(gz_sample.id).to eq 'd2682464'
12
+ expect(gz_sample.id).to eq '2682464'
13
13
  end
14
14
 
15
15
  it "has stars 5.0星级" do
@@ -34,7 +34,7 @@ describe Daodao::Hotel do
34
34
 
35
35
  #=====================================================================================================
36
36
  # hotel in beijing
37
- bj_sample = Daodao::Hotel.new("d3256870")
37
+ bj_sample = Daodao::Hotel.new("3256870")
38
38
 
39
39
  it "has name '北京怡亨酒店'" do
40
40
  expect(bj_sample.name).to eq '北京怡亨酒店'
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  describe Daodao do
3
- ranks = Daodao.rank('http://www.daodao.com/Hotel_Review-g298555-d2682464-Reviews-Four_Seasons_Hotel_Guangzhou-Guangzhou_Guangdong.html')
3
+ ranks = Daodao.rank('2682464')
4
+ puts ranks
4
5
  it "The first Ota name 'Booking.com' " do
5
6
  expect(ranks[:rank1]).to eq 'Booking.com'
6
7
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  describe Daodao::Rank do
3
- gz_sample = Daodao::Rank.new('/Hotel_Review-g298555-d2682464-Reviews-Four_Seasons_Hotel_Guangzhou-Guangzhou_Guangdong.html')
3
+ gz_sample = Daodao::Rank.new('2682464')
4
4
  details = gz_sample.rooms_details
5
5
  p gz_sample.rank
6
6
  # screen shot
@@ -38,8 +38,5 @@ describe Daodao::Rank do
38
38
  expect(details[4][:rooms_details][0][:room_price]).to eq 2330
39
39
  end
40
40
 
41
- it "has The hotel name '四季酒店'"do
42
- expect(gz_sample.name).to eq "四季酒店"
43
- end
44
41
 
45
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daodao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - timlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler