TaoBaoApi 0.0.4 → 0.0.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.
- data/README.md +1 -1
- data/lib/TaoBaoApi.rb +24 -18
- data/lib/TaoBaoApi/version.rb +1 -1
- data/test.rb +3 -2
- metadata +2 -2
data/README.md
CHANGED
data/lib/TaoBaoApi.rb
CHANGED
@@ -7,45 +7,51 @@ module TaoBaoApi
|
|
7
7
|
def get_info url
|
8
8
|
return 'good_url_nil' if url.nil?
|
9
9
|
|
10
|
+
url = url_filter(url)
|
10
11
|
doc = Nokogiri::HTML(open(url))
|
11
12
|
doc.encoding = 'utf-8'
|
12
|
-
|
13
|
+
|
13
14
|
begin
|
14
|
-
title = doc.css('.
|
15
|
+
title = doc.css('title').first.text.split('-').first.strip
|
15
16
|
rescue NoMethodError
|
16
17
|
return 'good_not_exists'
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
title = doc.css('title').first.text.split('-').first
|
21
|
-
|
20
|
+
images = []
|
22
21
|
if url.include? 'taobao'
|
23
22
|
price = doc.css('em.tb-rmb-num').first.text
|
24
|
-
|
23
|
+
img_src = 'data-src'
|
25
24
|
elsif url.include? 'tmall'
|
26
25
|
price = doc.css('.J_originalPrice').first.text.strip
|
27
|
-
|
26
|
+
img_src = 'src'
|
28
27
|
else
|
29
28
|
return 'good_url_is_not_taobao'
|
30
29
|
end
|
31
30
|
|
31
|
+
doc.css('#J_UlThumb').first.css('img').each do |img|
|
32
|
+
img = img.attr(img_src)
|
33
|
+
images << image_filter(img)
|
34
|
+
end
|
35
|
+
|
32
36
|
{:title => title,
|
33
37
|
:price => price,
|
34
|
-
:
|
38
|
+
:images => images,
|
35
39
|
:url => url}
|
36
40
|
end
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
filter_char = ["\n","\r","\t",' ']
|
44
|
-
filter_char.each do |s|
|
45
|
-
title = title.gsub(s,'')
|
46
|
-
end
|
42
|
+
private
|
43
|
+
def image_filter(imgUrl)
|
44
|
+
"#{imgUrl.split('.jpg').first}.jpg"
|
45
|
+
end
|
47
46
|
|
48
|
-
|
47
|
+
def url_filter(url)
|
48
|
+
if url.include?'s.click.taobao.com'
|
49
|
+
refer = open(url).base_uri.to_s.split('URL:').first
|
50
|
+
open(URI.unescape(refer.split('tu=')[1]),"Referer" => refer).base_uri.to_s.split('&ali_trackid=')[0]
|
51
|
+
else
|
52
|
+
url = url.split('/item.htm?').first + '/item.htm?id=' + url.split('id=').last.split('&').first
|
49
53
|
end
|
54
|
+
end
|
55
|
+
|
50
56
|
end
|
51
57
|
end
|
data/lib/TaoBaoApi/version.rb
CHANGED
data/test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'TaoBaoApi'
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'TaoBaoApi')
|
2
2
|
|
3
3
|
good = TaoBaoApi::Good.new
|
4
4
|
|
5
|
-
|
5
|
+
url = 'http://detail.tmall.com/item.htm?id=35576507007'
|
6
|
+
info = good.get_info url
|
6
7
|
|
7
8
|
p info
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TaoBaoApi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|