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 CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gsearch-parser"
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Diego Netto"]
@@ -3,9 +3,11 @@ require 'open-uri'
3
3
  require 'nokogiri'
4
4
 
5
5
  module GSearchParser
6
- def webSearch(query)
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
- # TODO: Fetch page
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
- @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
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gsearch-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: