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 +4 -4
- data/README.md +3 -3
- data/lib/daodao.rb +20 -9
- data/lib/daodao/hotel.rb +1 -1
- data/lib/daodao/hotel_list.rb +1 -1
- data/lib/daodao/rank.rb +42 -33
- data/lib/daodao/version.rb +1 -1
- data/spec/hotel_spec.rb +3 -3
- data/spec/rank_fast_spec.rb +2 -1
- data/spec/rank_spec.rb +1 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b7e9eacbf6cbe5bbfc30e566447703171f97c88
|
4
|
+
data.tar.gz: 6b3d10c511674c81b83d3776fb7d894540a823f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
32
|
-
sample = Daodao::Rank.new(
|
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
|
38
|
+
`Note:` You can pass other hotel_id to `initialize` representing the hotel page.
|
39
39
|
|
40
40
|
#### Get ota's ranking
|
41
41
|
|
data/lib/daodao.rb
CHANGED
@@ -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(
|
11
|
-
|
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] =
|
14
|
-
row[:hotel_name] = page.xpath('//span[@itemprop="name"]').text
|
14
|
+
row[:hotel_id] = hotel_id[/\d+/]
|
15
15
|
rank=1
|
16
|
-
|
17
|
-
|
18
|
-
row[
|
19
|
-
|
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
|
data/lib/daodao/hotel.rb
CHANGED
@@ -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
|
9
|
+
@url = URI("http://daodao.com/Hotel_Review-d#{hotel_id}")
|
10
10
|
@pages = Nokogiri::HTML(open(@url))
|
11
11
|
end
|
12
12
|
|
data/lib/daodao/hotel_list.rb
CHANGED
data/lib/daodao/rank.rb
CHANGED
@@ -2,33 +2,59 @@ module Daodao
|
|
2
2
|
class Rank
|
3
3
|
include Capybara::DSL
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
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
|
-
|
13
|
-
|
14
|
-
page.visit
|
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("
|
21
|
-
puts '展开报价...'
|
20
|
+
page.all("//span[text()='展开报价']").each do |layout|
|
22
21
|
layout.trigger('click')
|
23
22
|
end
|
24
|
-
@
|
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
|
-
@
|
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 = @
|
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
|
data/lib/daodao/version.rb
CHANGED
data/spec/hotel_spec.rb
CHANGED
@@ -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("
|
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 '
|
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("
|
37
|
+
bj_sample = Daodao::Hotel.new("3256870")
|
38
38
|
|
39
39
|
it "has name '北京怡亨酒店'" do
|
40
40
|
expect(bj_sample.name).to eq '北京怡亨酒店'
|
data/spec/rank_fast_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe Daodao do
|
3
|
-
ranks = Daodao.rank('
|
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
|
data/spec/rank_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe Daodao::Rank do
|
3
|
-
gz_sample = Daodao::Rank.new('
|
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.
|
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-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|