metainspector 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/Rakefile +1 -0
- data/lib/metainspector.rb +12 -4
- metadata +11 -2
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 1.0.2 / 2007-12-10
|
2
|
+
|
3
|
+
* Open-uri, Rubygems and Hpricot required at the MetaInspector class, so you won't need to require them. Just require metainspector and they will be included along.
|
4
|
+
|
5
|
+
* Rescue in case of socket error. If the URL does not exist or is unreachable, it will catch the SocketError exception and return 'ok' => false.
|
6
|
+
|
7
|
+
* Added hpricot as extra dependency so it will be automatically installed when you install the metainspector gem.
|
8
|
+
|
9
|
+
* Misc code cleanup... "if !doc.at('title').nil?" is the same as "if doc.at('title')"
|
10
|
+
|
11
|
+
* Thanks to David Calavera (http://thinkincode.net) and Juan Alvarez (http://ruby.reboot.com.mx/) for their comments and contributions to this release.
|
12
|
+
|
1
13
|
== 1.0.1 / 2007-12-06
|
2
14
|
|
3
15
|
* Added some info at README.txt, translated all methods to English
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ Hoe.new('metainspector', MetaInspector::VERSION) do |p|
|
|
14
14
|
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
15
15
|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
16
16
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
p.extra_deps << "hpricot"
|
17
18
|
end
|
18
19
|
|
19
20
|
# vim: syntax=Ruby
|
data/lib/metainspector.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
class MetaInspector
|
2
|
-
|
2
|
+
require 'open-uri'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hpricot'
|
5
|
+
|
6
|
+
VERSION = '1.0.2'
|
3
7
|
|
4
8
|
Hpricot.buffer_size = 300000
|
5
9
|
|
@@ -7,21 +11,21 @@ class MetaInspector
|
|
7
11
|
doc = Hpricot(open(url))
|
8
12
|
|
9
13
|
# Searching title...
|
10
|
-
if
|
14
|
+
if doc.at('title')
|
11
15
|
title = doc.at('title').inner_html
|
12
16
|
else
|
13
17
|
title = ""
|
14
18
|
end
|
15
19
|
|
16
20
|
# Searching meta description...
|
17
|
-
if
|
21
|
+
if doc.at("meta[@name='description']")
|
18
22
|
description = doc.at("meta[@name='description']")['content']
|
19
23
|
else
|
20
24
|
description = ""
|
21
25
|
end
|
22
26
|
|
23
27
|
# Searching meta keywords...
|
24
|
-
if
|
28
|
+
if doc.at("meta[@name='keywords']")
|
25
29
|
keywords = doc.at("meta[@name='keywords']")['content']
|
26
30
|
else
|
27
31
|
keywords = ""
|
@@ -35,5 +39,9 @@ class MetaInspector
|
|
35
39
|
|
36
40
|
# Returning all data...
|
37
41
|
{'ok' => true, 'title' => title, 'description' => description, 'keywords' => keywords, 'links' => links}
|
42
|
+
|
43
|
+
rescue SocketError
|
44
|
+
puts 'MetaInspector exception: The url provided does not exist or is temporarily unavailable (socket error)'
|
45
|
+
{'ok' => false, 'title' => nil, 'description' => nil, 'keywords' => nil, 'links' => nil}
|
38
46
|
end
|
39
47
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: metainspector
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-12-
|
6
|
+
version: 1.0.2
|
7
|
+
date: 2007-12-10 00:00:00 +01:00
|
8
8
|
summary: Ruby gem for web scraping purposes. It scrapes a given URL, and returns you a hash with data from it like for example the title, meta description, meta keywords, an array with all the links, all the images in it, etc.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -52,6 +52,15 @@ extensions: []
|
|
52
52
|
requirements: []
|
53
53
|
|
54
54
|
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hpricot
|
57
|
+
version_requirement:
|
58
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.0.0
|
63
|
+
version:
|
55
64
|
- !ruby/object:Gem::Dependency
|
56
65
|
name: hoe
|
57
66
|
version_requirement:
|