lib/gsearch-parser.rb in gsearch-parser-0.3.1 vs lib/gsearch-parser.rb in gsearch-parser-0.3.2
- old
+ new
@@ -15,18 +15,17 @@
#
# Google Web Search class
#
class GoogleWebSearch
- attr_accessor :results, :currentPage
- @index
-
+ attr_accessor :results, :nextURI
+ @currentPage
+
# Class initializer
def initialize(query)
# Initialize variables
@results = Array.new
- @index = 0
# Update the results list: (Fetch, Store, and Parse)
updateResults("http://google.com/search?sourceid=chrome&q=#{query}")
end
@@ -76,17 +75,17 @@
return currentResults
end
# Parse the results from the next page and append to results list
def nextResults
- # Parse next result page link
- nextPageUrl = @currentPage.css("table#nav tr td a")[@index]['href']
+ # Parse next result page link from the currently marked one
+ nextPagePath = @currentPage.at_css("table#nav tr td.cur").next_sibling().at_css("a")['href']
- # Increment reference index
- @index += 1
+ # Construct the URI
+ @nextURI = "http://www.google.com" + nextPagePath
# Update results
- updateResults("http://www.google.com" + nextPageUrl)
+ updateResults(@nextURI)
end
# Iterator over results
def each(&blk)
@results.each(&blk)