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 CHANGED
@@ -9,7 +9,7 @@ ruby 1.9.3 2.0.0未测试,可能会有问题
9
9
 
10
10
  在 Gemfile 文件中加入以下代码:
11
11
 
12
- gem "TaoBaoApi", "~> 0.0.3"
12
+ gem "TaoBaoApi"
13
13
 
14
14
  然后执行:
15
15
 
@@ -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
- # p doc
13
+
13
14
  begin
14
- title = doc.css('.tb-detail-hd').first.text
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
- #title = title_fiter(title.strip)
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
- img = doc.css('#J_ImgBooth').first.attr('data-src')
23
+ img_src = 'data-src'
25
24
  elsif url.include? 'tmall'
26
25
  price = doc.css('.J_originalPrice').first.text.strip
27
- img = doc.css('#J_ImgBooth').first.attr('src')
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
- :img => img,
38
+ :images => images,
35
39
  :url => url}
36
40
  end
37
41
 
38
- private
39
- #deprecated
40
- def title_fiter(title)
41
- title = title.split("\r\n")[0]
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
- title
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
@@ -1,3 +1,3 @@
1
1
  module TaoBaoApi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
- info = good.get_info 'http://item.taobao.com/item.htm?id=16434110195'
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
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-19 00:00:00.000000000 Z
12
+ date: 2014-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler