googling 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/googling +16 -0
- data/lib/googling/result.rb +11 -0
- data/lib/googling/search.rb +42 -0
- data/lib/googling/version.rb +1 -1
- data/lib/googling.rb +5 -23
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1239809d6bd5fdd5244bc8d1ee1278954ef5e7
|
4
|
+
data.tar.gz: 1b42f28f71f13fc49c75fb5375e538fe2c603627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89d80a2f8f10aee28443fd0111868617a79c4d3d0da9db92c9e8e54397c39ed9853661d142bab3c3883a4754a82cf585d93db6a32ec143b17b99f83ab4e62534
|
7
|
+
data.tar.gz: 698781c78cd3e4c3725015449128a3e25f4094903f06b51d38f112ac361d71a36be2d5292d7980b627e3a4a24e9b48a264701d0195e350446d9970bda4e0e0ff
|
data/bin/googling
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# The command line Googling tool.
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
5
|
+
require 'googling'
|
6
|
+
|
7
|
+
puts "please enter the KEY WORDS."
|
8
|
+
keywords = gets.chomp('')
|
9
|
+
|
10
|
+
results = Googling.search(keywords)
|
11
|
+
results.each do |result|
|
12
|
+
puts ">>>> "
|
13
|
+
puts result.title
|
14
|
+
puts result.link
|
15
|
+
puts result.description
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require "net/http"
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Googling
|
6
|
+
class Search
|
7
|
+
attr_reader :response, :list
|
8
|
+
|
9
|
+
def initialize(keywords)
|
10
|
+
@keywords = keywords
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
make_request
|
15
|
+
parse_results
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def make_request
|
21
|
+
uri = URI.parse("https://www.google.com/search?q=#{@keywords}")
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
+
http.use_ssl = true
|
24
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
+
@response = http.request(request)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_results
|
29
|
+
page = Nokogiri::HTML(response.body)
|
30
|
+
page.encoding = 'utf-8'
|
31
|
+
|
32
|
+
nodes = page.css('li.g')
|
33
|
+
nodes = nodes.select { |r| r.css('table').empty? }
|
34
|
+
nodes.map do |r|
|
35
|
+
title = r.css('h3 a').text
|
36
|
+
link = r.css('h3 a').map{|x| x['href'].to_s.sub!("/url?q=","")}
|
37
|
+
description = r.css('div.s span.st').text
|
38
|
+
Result.new(title: title, link: link, description: description)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/googling/version.rb
CHANGED
data/lib/googling.rb
CHANGED
@@ -1,27 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'googling/search'
|
2
|
+
require 'googling/result'
|
2
3
|
|
3
4
|
module Googling
|
4
|
-
def self.check
|
5
|
-
check = `html2text -version` rescue nil
|
6
|
-
if check
|
7
|
-
puts "Fine, go next step."
|
8
|
-
true
|
9
|
-
else
|
10
|
-
puts "Please install the html2text."
|
11
|
-
false
|
12
|
-
end
|
13
|
-
end
|
14
5
|
|
15
|
-
def self.search
|
16
|
-
|
17
|
-
yoursearch = gets.chomp()
|
18
|
-
url = "curl -A Mozilla http://www.google.com/search?q=#{yoursearch} |html2text -width 70"
|
19
|
-
answer = `curl #{url}`
|
20
|
-
puts "#{answer}"
|
6
|
+
def self.search(keywords)
|
7
|
+
Googling::Search.new(keywords).execute
|
21
8
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
if Googling.check
|
25
|
-
puts Googling.search
|
26
|
-
end
|
27
|
-
|
9
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Imyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -41,7 +41,8 @@ dependencies:
|
|
41
41
|
description: Write a longer description. Optional.
|
42
42
|
email:
|
43
43
|
- smilestar8@hotmail.com
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- googling
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -50,8 +51,11 @@ files:
|
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
54
|
+
- bin/googling
|
53
55
|
- googling.gemspec
|
54
56
|
- lib/googling.rb
|
57
|
+
- lib/googling/result.rb
|
58
|
+
- lib/googling/search.rb
|
55
59
|
- lib/googling/version.rb
|
56
60
|
homepage: ''
|
57
61
|
licenses:
|