amazon-search 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amazon-search.rb +16 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d9464f71fde7ee69a0859f396294c5314751886
|
4
|
+
data.tar.gz: c5bc777baa5e07f64abea86e4cf450384e1e2c30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1193508bd1dca50f242cf88da56cc9aeb1e159917a800f91dd403ff92a421588b7ac67bf3f35c2d12fb3aca0ef178027c4719067aa1c24d9e5fd549f1380687d
|
7
|
+
data.tar.gz: 407a8b0fecee06bbe4b71bbf39cd6a484e75c266c4e5595bf738733439c0aef2a6086769e79cea10fb6612bf782666dbcfd90a3873a2a8daaa26bc517deb1f53
|
data/lib/amazon-search.rb
CHANGED
@@ -4,24 +4,27 @@ require 'mechanize'
|
|
4
4
|
require 'thor'
|
5
5
|
|
6
6
|
def search(keywords)
|
7
|
-
###########################################
|
8
|
-
# Select Amazon search form and submit
|
9
|
-
# the search criteria
|
10
|
-
###########################################
|
11
7
|
|
12
|
-
agent = Mechanize.new
|
13
|
-
main_page = agent.get("http://amazon.com")
|
14
|
-
search_form = main_page.form_with :name => "site-search"
|
15
8
|
|
16
|
-
if keywords.nil?
|
9
|
+
if keywords.nil? # did user forget to enter in search keywords?
|
10
|
+
STDOUT.puts """
|
11
|
+
Please provide search keywords
|
12
|
+
|
13
|
+
Example Usage:
|
14
|
+
search watches
|
15
|
+
search books
|
16
|
+
search games
|
17
|
+
|
18
|
+
"""
|
19
|
+
else
|
20
|
+
|
21
|
+
agent = Mechanize.new
|
22
|
+
main_page = agent.get("http://amazon.com")
|
23
|
+
search_form = main_page.form_with :name => "site-search" # find the search form in Amazon
|
24
|
+
|
17
25
|
search_form.field_with(:name => "field-keywords").value = keywords # sets value of search box
|
18
26
|
search_results = agent.submit search_form # submits form
|
19
27
|
|
20
|
-
###########################################
|
21
|
-
# Cycle through all result pages
|
22
|
-
# and list product links
|
23
|
-
###########################################
|
24
|
-
|
25
28
|
next_page = agent.get(search_results.uri) # initial search results are the first page
|
26
29
|
|
27
30
|
# last page is disabled nav button in search results
|
@@ -100,17 +103,5 @@ if keywords.nil? false # did user enter in search keywords?
|
|
100
103
|
|
101
104
|
puts "\n\n(end of search results)"
|
102
105
|
|
103
|
-
else # user didn't enter search keywords
|
104
|
-
|
105
|
-
STDOUT.puts <<-EOF
|
106
|
-
Please provide search keywords
|
107
|
-
|
108
|
-
Example Usage:
|
109
|
-
search watches
|
110
|
-
search books
|
111
|
-
search games
|
112
|
-
|
113
|
-
EOF
|
114
|
-
|
115
106
|
end # ends ARGV if statement
|
116
107
|
end
|