amazon-search 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.rdoc +28 -0
- metadata +3 -3
- data/lib/amazon-search.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3068a04c89932a4bdc33a02ef8e476c10df10c0
|
4
|
+
data.tar.gz: 06fe06cbd83975ea2481145623d8ed43afd7ffb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc285ff02ee0aa503f9e7c6064f60df8d004044f24ca04182fd8811150030d47e77380ce727aa265cd7a9f304954b0745c40bd04f02c63da33757e5b4ff5326
|
7
|
+
data.tar.gz: 17f7e49d945badcaadd287df3135c247b26eadb68b55c4c92e014967676b402c6a69f58837e5b8e6cdd4380c229d12824d8a101d40be2e5881f8abf80e5bb307
|
data/Readme.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== amazon-search
|
2
|
+
|
3
|
+
Amazon Search is a simple Ruby tool to search for Amazon products.
|
4
|
+
|
5
|
+
This is a tool that does not require configuration of Amazon's API. The functionality is centered around mechanize pagination for the screen scraping of nokogiri elements. XML and CSS selectors are currently being used. In the event that Amazon updates their site, the selectors will need to be updated.
|
6
|
+
|
7
|
+
== INSTALLATION
|
8
|
+
|
9
|
+
$ gem install amazon-search
|
10
|
+
|
11
|
+
== EXAMPLE
|
12
|
+
|
13
|
+
require 'amazon/search'
|
14
|
+
|
15
|
+
# Search for products by keywords and store results
|
16
|
+
Amazon::Search.find_products "ruby"
|
17
|
+
|
18
|
+
|
19
|
+
# puts results
|
20
|
+
Amazon::Search.display_results
|
21
|
+
|
22
|
+
== MIT LICENSE
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
25
|
+
|
26
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
27
|
+
|
28
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mason
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -31,7 +31,7 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
-
|
34
|
+
- Readme.rdoc
|
35
35
|
homepage: https://github.com/m8ss/amazon-search
|
36
36
|
licenses:
|
37
37
|
- MIT
|
data/lib/amazon-search.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'mechanize'
|
4
|
-
|
5
|
-
puts """
|
6
|
-
Example usage:
|
7
|
-
|
8
|
-
search \"books\"
|
9
|
-
search \"Enders Game\"
|
10
|
-
search \"Rolex\"
|
11
|
-
|
12
|
-
"""
|
13
|
-
|
14
|
-
def search(keywords)
|
15
|
-
agent = Mechanize.new
|
16
|
-
main_page = agent.get("http://amazon.com")
|
17
|
-
search_form = main_page.form_with :name => "site-search" # find the search form in Amazon
|
18
|
-
|
19
|
-
search_form.field_with(:name => "field-keywords").value = keywords # sets value of search box
|
20
|
-
search_results = agent.submit search_form # submits form
|
21
|
-
|
22
|
-
next_page = agent.get(search_results.uri) # initial search results are the first page
|
23
|
-
|
24
|
-
# last page is disabled nav button in search results
|
25
|
-
last_page_num = search_results.search '//*[contains(concat( " ", @class, " " ), concat( " ", "pagnDisabled", " " ))]'
|
26
|
-
last_page_num = last_page_num.text.to_i # change to int for upcoming iteration instructions
|
27
|
-
|
28
|
-
count = 0 # start count variable
|
29
|
-
|
30
|
-
last_page_num.times do # loop forever until stopped
|
31
|
-
count += 1
|
32
|
-
|
33
|
-
page = agent.get(next_page.uri) # load the next page
|
34
|
-
|
35
|
-
#--------- display page number ---------------------
|
36
|
-
# current_page = page.search '//*[contains(concat( " ", @class, " " ), concat( " ", "pagnCur", " " ))]'
|
37
|
-
# STDOUT.puts "\n", "=="*50
|
38
|
-
# STDOUT.puts "Displaying '#{current_page.text}' of '20' pages"
|
39
|
-
# STDOUT.puts "This is the current page's uri:"
|
40
|
-
# STDOUT.puts page.uri
|
41
|
-
|
42
|
-
product_divs = page.search('//li[starts-with(@id, "result")]') # find the div of each product
|
43
|
-
|
44
|
-
# nokogiri syntax is needed when iterating...not mechanize!
|
45
|
-
product_divs.each do |product|
|
46
|
-
|
47
|
-
#--------- nokogiri select html sections from css ---------------------
|
48
|
-
title = product.at_css(".s-access-title")
|
49
|
-
seller = product.at_css(".a-row > .a-spacing-none") #".a-spacing-small .a-spacing-none"
|
50
|
-
price = product.at_css(".s-price")
|
51
|
-
stars = product.at_css(".a-icon-star")
|
52
|
-
reviews = product.at_css("span+ .a-text-normal") # ".a-span-last .a-spacing-mini > span+ .a-text-normal"
|
53
|
-
image = product.at_css(".s-access-image")
|
54
|
-
url = product.at_css(".a-row > a")
|
55
|
-
|
56
|
-
if title == nil # if it's nil it's prob an ad
|
57
|
-
break
|
58
|
-
else
|
59
|
-
title = title.text
|
60
|
-
|
61
|
-
if seller == nil # if seller is nil put unknown
|
62
|
-
seller = "Unknown"
|
63
|
-
else
|
64
|
-
seller = seller.text
|
65
|
-
if price == nil # no price? prob not worthy item
|
66
|
-
break
|
67
|
-
|
68
|
-
else
|
69
|
-
price = price.text
|
70
|
-
if stars == nil
|
71
|
-
break
|
72
|
-
|
73
|
-
else
|
74
|
-
stars = stars.text
|
75
|
-
reviews = reviews.text
|
76
|
-
image = image['src']
|
77
|
-
url = url['href']
|
78
|
-
|
79
|
-
STDOUT.puts "--"*50
|
80
|
-
STDOUT.puts "title: \t\t#{title}"
|
81
|
-
STDOUT.puts "seller: \t#{seller}"
|
82
|
-
STDOUT.puts "price: \t\t#{price}"
|
83
|
-
STDOUT.puts "stars: \t\t#{stars}"
|
84
|
-
STDOUT.puts "reviews: \t#{reviews}"
|
85
|
-
STDOUT.puts "image url: \t#{image}"
|
86
|
-
STDOUT.puts "product url: \t#{url}"
|
87
|
-
|
88
|
-
end # ends nil price if statement
|
89
|
-
end # ends nil stars if statement
|
90
|
-
end # ends nil seller if statement
|
91
|
-
end # ends nil product if statement
|
92
|
-
end # ends each product div iteration (page is finished)
|
93
|
-
|
94
|
-
next_page_link = page.link_with text: /Next Page/ # find the next page link
|
95
|
-
next_page = next_page_link.click unless count == 20 # click to next page unless on page 20
|
96
|
-
end # ends pagination loop
|
97
|
-
|
98
|
-
puts "\n\n(end of search results)"
|
99
|
-
end
|