GetTaoBaoProduct 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/GetTaoBaoProduct.gemspec +25 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/GetTaoBaoProduct.rb +49 -0
- data/lib/GetTaoBaoProduct/version.rb +3 -0
- data/test.rb +7 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 82f8b03467644bb1fd0c5b6617436cd4849322ce
|
|
4
|
+
data.tar.gz: d5ea66b0ea397de42b35cf7c9c6d82161dc2fa16
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0e2500e65d0d1d8d9665139e3ebb2b8f8ebe71054c4a924c08d8bba661b26c4c38ae1fdafa798b07e147a01ea38397517cc86909f6d304829a34b21044ce0927
|
|
7
|
+
data.tar.gz: 6de0ac30a3dfd43d599891999f81f10644f63e11fb2fc22d435521202d4a43bf544663f29c2004bc4602a9afa8318be6692e6baf141e6c518c23ccd2862b1035
|
data/.gitignore
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'GetTaoBaoProduct/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "GetTaoBaoProduct"
|
|
8
|
+
spec.version = GetTaoBaoProduct::VERSION
|
|
9
|
+
spec.authors = ["Jeffson"]
|
|
10
|
+
spec.email = ["randeeshen@gmail.com"]
|
|
11
|
+
spec.description = %q{get taobao product info }
|
|
12
|
+
spec.summary = %q{get taobao product info with url}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
|
|
24
|
+
spec.add_dependency "nokogiri", ">=2.0.0"
|
|
25
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 randee
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# GetTaoBaoProduct
|
|
2
|
+
|
|
3
|
+
通过淘宝或天猫商品链接获取商品信息,商品信息包括标题、价格、图片。
|
|
4
|
+
|
|
5
|
+
## 环境说明
|
|
6
|
+
ruby 2.0.0
|
|
7
|
+
|
|
8
|
+
## 安装方法
|
|
9
|
+
|
|
10
|
+
在 Gemfile 文件中加入以下代码:
|
|
11
|
+
|
|
12
|
+
gem "GetTaoBaoProduct", "~> 0.0.3"
|
|
13
|
+
|
|
14
|
+
然后执行:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
或者你可以通过 gem installl 直接安装:
|
|
19
|
+
|
|
20
|
+
$ gem install GetTaoBaoProduct
|
|
21
|
+
|
|
22
|
+
## 使用方法
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
|
|
26
|
+
require 'GetTaoBaoProduct'
|
|
27
|
+
|
|
28
|
+
item = GetTaoBaoProduct::Item.new
|
|
29
|
+
|
|
30
|
+
info = item.get_info 'http://item.taobao.com/item.htm?id=16434110195'
|
|
31
|
+
|
|
32
|
+
p info #hash format,{ title: xxx, price: xxx, img: xxx, url: url }
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
测试文件见test.rb
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require "GetTaoBaoProduct/version"
|
|
2
|
+
|
|
3
|
+
module GetTaoBaoProduct
|
|
4
|
+
class Item
|
|
5
|
+
def get_info url
|
|
6
|
+
return 'product_url_nil' if url.nil?
|
|
7
|
+
|
|
8
|
+
doc = Nokogiri::HTML(open(url))
|
|
9
|
+
doc.encoding = 'utf-8'
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
title = doc.css('.tb-detail-hd').first.text
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
return 'product_not_exists'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
title = title_fiter(title.strip)
|
|
18
|
+
|
|
19
|
+
if url.include? 'taobao' #淘宝
|
|
20
|
+
price = doc.css('em.tb-rmb-num').first.text
|
|
21
|
+
img = doc.css('#J_ImgBooth').first.attr('data-src')
|
|
22
|
+
elsif url.include? 'tmall' #天猫
|
|
23
|
+
price = doc.css('.J_originalPrice').first.text.strip
|
|
24
|
+
img = doc.css('#J_ImgBooth').first.attr('src')
|
|
25
|
+
else
|
|
26
|
+
return 'product_url_is_not_taobao'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
{
|
|
30
|
+
title: title,
|
|
31
|
+
price: price,
|
|
32
|
+
img: img,
|
|
33
|
+
url: url
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
def title_fiter(title)
|
|
39
|
+
title = title.split("\r\n")[0]
|
|
40
|
+
|
|
41
|
+
filter_char = ["\n","\r","\t",' ']
|
|
42
|
+
filter_char.each do |s|
|
|
43
|
+
title = title.gsub(s,'')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
title
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/test.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: GetTaoBaoProduct
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jeffson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: nokogiri
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 2.0.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 2.0.0
|
|
55
|
+
description: 'get taobao product info '
|
|
56
|
+
email:
|
|
57
|
+
- randeeshen@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- GetTaoBaoProduct.gemspec
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/GetTaoBaoProduct.rb
|
|
69
|
+
- lib/GetTaoBaoProduct/version.rb
|
|
70
|
+
- test.rb
|
|
71
|
+
homepage: ''
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata: {}
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - '>='
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - '>='
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubyforge_project:
|
|
91
|
+
rubygems_version: 2.0.3
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: get taobao product info with url
|
|
95
|
+
test_files: []
|