gsearch-parser 0.0.2 → 0.0.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 +59 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/gsearch-parser.gemspec
CHANGED
data/lib/gsearch-parser.rb
CHANGED
@@ -1,7 +1,63 @@
|
|
1
1
|
require "gsearch-parser/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
2
4
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
5
|
+
module GSearchParser
|
6
|
+
def webSearch(query)
|
7
|
+
GoogleSearch.new(query)
|
6
8
|
end
|
7
9
|
end
|
10
|
+
|
11
|
+
###################################################
|
12
|
+
# #
|
13
|
+
# GoogleSearch Class #
|
14
|
+
# #
|
15
|
+
###################################################
|
16
|
+
class GoogleSearch
|
17
|
+
attr_accessor :results
|
18
|
+
|
19
|
+
# Class initializer
|
20
|
+
def initialize(query)
|
21
|
+
# Initialize array
|
22
|
+
@results = Array.new
|
23
|
+
|
24
|
+
# TODO: Format query
|
25
|
+
|
26
|
+
# TODO: Fetch page
|
27
|
+
searchPage = Nokogiri::HTML(open("http://google.com/search?q=#{query}"))
|
28
|
+
|
29
|
+
@results << Result.new('title', 'content', "http://www.google.com")
|
30
|
+
|
31
|
+
# Iterate over all search result divs and parse content into Result objects,
|
32
|
+
# and finally store these in the results array
|
33
|
+
#searchPage.css('li.g > div.vsc').each do |result|
|
34
|
+
# title = result.css('h3.r > a.l').content
|
35
|
+
#content = result.css('div.s > span.st').content
|
36
|
+
#@results << Result.new('title', 'content', "http://www.google.com")
|
37
|
+
#end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Iterator over results
|
41
|
+
def each(&blk)
|
42
|
+
@results.each(&blk)
|
43
|
+
end
|
44
|
+
|
45
|
+
###################################################
|
46
|
+
# #
|
47
|
+
# Result Class #
|
48
|
+
# #
|
49
|
+
###################################################
|
50
|
+
class Result
|
51
|
+
attr_accessor :title, :content, :uri
|
52
|
+
|
53
|
+
# Class initializer
|
54
|
+
def initialize(title, content, uri)
|
55
|
+
@title = title
|
56
|
+
@content = content
|
57
|
+
@uri = uri
|
58
|
+
end
|
59
|
+
|
60
|
+
end # Result
|
61
|
+
|
62
|
+
end # GoogleSearch
|
63
|
+
|