gsearch-parser 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/gsearch-parser.gemspec +1 -1
- data/lib/gsearch-parser.rb +14 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/gsearch-parser.gemspec
CHANGED
data/lib/gsearch-parser.rb
CHANGED
@@ -29,11 +29,22 @@ class GoogleSearch
|
|
29
29
|
searchPage = Nokogiri::HTML(open("http://google.com/search?sourceid=chrome&q=#{query}",
|
30
30
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19'))
|
31
31
|
|
32
|
-
# Iterate over each Google result list element
|
32
|
+
# Iterate over each Google result list element
|
33
33
|
searchPage.css('li.g').each do |result|
|
34
|
-
|
34
|
+
# Extract the title
|
35
|
+
title = result.css('h3').first.inner_html
|
36
|
+
|
37
|
+
# Extract the content. There is the possibility for
|
38
|
+
# the content to be nil, so check for this
|
35
39
|
content = result.css('span.st').first
|
36
|
-
|
40
|
+
if !content
|
41
|
+
content = ''
|
42
|
+
end
|
43
|
+
|
44
|
+
# Extract the URI
|
45
|
+
uri = result.css('cite').first.inner_html
|
46
|
+
|
47
|
+
# Create a new Result object and append to the array
|
37
48
|
@results << Result.new(title, content, uri)
|
38
49
|
end
|
39
50
|
end
|