gsearch-parser 0.0.3 → 0.1.0
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 +13 -12
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/gsearch-parser.gemspec
CHANGED
data/lib/gsearch-parser.rb
CHANGED
@@ -3,9 +3,11 @@ require 'open-uri'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
5
|
module GSearchParser
|
6
|
-
|
6
|
+
|
7
|
+
def GSearchParser.webSearch(query)
|
7
8
|
GoogleSearch.new(query)
|
8
9
|
end
|
10
|
+
|
9
11
|
end
|
10
12
|
|
11
13
|
###################################################
|
@@ -23,18 +25,17 @@ class GoogleSearch
|
|
23
25
|
|
24
26
|
# TODO: Format query
|
25
27
|
|
26
|
-
#
|
27
|
-
searchPage = Nokogiri::HTML(open("http://google.com/search?q=#{query}"
|
28
|
+
# Fetch page
|
29
|
+
searchPage = Nokogiri::HTML(open("http://google.com/search?sourceid=chrome&q=#{query}",
|
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'))
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#@results << Result.new('title', 'content', "http://www.google.com")
|
37
|
-
#end
|
32
|
+
# Iterate over each Google result list element and extract data
|
33
|
+
searchPage.css('li.g').each do |result|
|
34
|
+
title = result.css('h3').first.content
|
35
|
+
content = result.css('span.st').first.inner_html
|
36
|
+
uri = result.css('cite').inner_html
|
37
|
+
@results << Result.new(title, content, uri)
|
38
|
+
end
|
38
39
|
end
|
39
40
|
|
40
41
|
# Iterator over results
|