htmltools 1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +58 -0
- data/README +162 -0
- data/demo/degolive.rb +89 -0
- data/demo/ebaySearch.rb +93 -0
- data/demo/xpath.rb +62 -0
- data/lib/html/element.rb +323 -0
- data/lib/html/rexml-nodepath.rb +49 -0
- data/lib/html/sgml-parser.rb +372 -0
- data/lib/html/stparser.rb +280 -0
- data/lib/html/tags.rb +288 -0
- data/lib/html/tree.rb +140 -0
- data/lib/html/xmltree.rb +173 -0
- data/lib/html/xpath.rb +72 -0
- data/test/suite.rb +5 -0
- data/test/tc_html-element.rb +73 -0
- data/test/tc_html-tree.rb +201 -0
- data/test/tc_source-parser.rb +160 -0
- data/test/tc_stacking-parser.rb +196 -0
- data/test/tc_xpath.rb +87 -0
- metadata +58 -0
data/test/tc_xpath.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Copyright:: Copyright (C) 2002, Ned Konz <ned@bike-nomad.com>
|
3
|
+
# License:: Same as Ruby's
|
4
|
+
# CVS ID: $Id: tc_xpath.rb,v 1.6 2004/09/10 17:29:37 jhannes Exp $
|
5
|
+
#
|
6
|
+
# This is the test file for the HTMLTree XPath interface.
|
7
|
+
#
|
8
|
+
require 'html/tree'
|
9
|
+
require 'html/xpath'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'html/rexml-nodepath'
|
12
|
+
|
13
|
+
|
14
|
+
$sample1 = %q{
|
15
|
+
<html>
|
16
|
+
<head>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<ul compact="compact">
|
20
|
+
<li>An item</li>
|
21
|
+
</ul>
|
22
|
+
<hr>
|
23
|
+
<img src="http://wherever">
|
24
|
+
<p class='123'>A < paragraph
|
25
|
+
<p class='234'>Another paragraph
|
26
|
+
</body>
|
27
|
+
</html>
|
28
|
+
}
|
29
|
+
|
30
|
+
class XPathTestCase < Test::Unit::TestCase
|
31
|
+
attr_accessor :p
|
32
|
+
|
33
|
+
def setup
|
34
|
+
@p = HTMLTree::Parser.new(true, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_basic
|
38
|
+
p.feed("<html></html>")
|
39
|
+
t = p.tree
|
40
|
+
assert_same(HTMLTree::Document, t.class)
|
41
|
+
d = t.as_rexml_document
|
42
|
+
assert_same(REXML::Document, d.class)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_match1
|
46
|
+
p.feed($sample1)
|
47
|
+
d = p.tree.as_rexml_document
|
48
|
+
m = d.root.get_elements( '//p' )
|
49
|
+
assert_equal(2, m.size)
|
50
|
+
assert_equal('p', m.first.name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_match2
|
54
|
+
p.feed($sample1)
|
55
|
+
m = match('/html/body/p')
|
56
|
+
assert_equal(2, m.size)
|
57
|
+
assert_equal('p', m.first.name)
|
58
|
+
assert_equal('123', m[0].attributes['class'])
|
59
|
+
assert_equal('234', m[1].attributes['class'])
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_match_all
|
63
|
+
p.feed($sample1)
|
64
|
+
html = p.tree.html_node
|
65
|
+
m = html.rexml_match('descendant::node()')
|
66
|
+
#m.each { |ea| puts ea.full_path + " --> " + ea.to_s }
|
67
|
+
assert_equal(11, m.size)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_find_by_attribute
|
71
|
+
p.feed($sample1)
|
72
|
+
assert_equal("Another paragraph", match("/html/body/p[@class = '234']/text()").to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_show_attribute
|
76
|
+
p.feed("<html><body><ol>" +
|
77
|
+
"<li item='1'><a href='http://wrong.com'>test</a></li>" +
|
78
|
+
"<li item='2'><a href='http://test.com'>test</a></li>" +
|
79
|
+
"<li item='3'><a href='http://wrong.com'>test</a></li>" +
|
80
|
+
"</ol></body></html>")
|
81
|
+
assert_equal('http://test.com', match("//li[@item = '2']/a/@href")[0].value)
|
82
|
+
end
|
83
|
+
|
84
|
+
def match(xpath)
|
85
|
+
p.tree.rexml_match(xpath)
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: htmltools
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "1.10"
|
7
|
+
date: 2006-07-25 00:00:00 +02:00
|
8
|
+
summary: This is a Ruby library for building trees representing HTML structure.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- lib
|
12
|
+
email: johannes@brodwall.com
|
13
|
+
homepage: http://ruby-htmltools.rubyforge.org/
|
14
|
+
rubyforge_project:
|
15
|
+
description:
|
16
|
+
autorequire: html/tree
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: false
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
-
|
23
|
+
- ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
30
|
+
authors:
|
31
|
+
- Johannes Brodwall
|
32
|
+
files:
|
33
|
+
- demo/degolive.rb
|
34
|
+
- demo/ebaySearch.rb
|
35
|
+
- demo/xpath.rb
|
36
|
+
- INSTALL
|
37
|
+
- lib/html/element.rb
|
38
|
+
- lib/html/rexml-nodepath.rb
|
39
|
+
- lib/html/sgml-parser.rb
|
40
|
+
- lib/html/stparser.rb
|
41
|
+
- lib/html/tags.rb
|
42
|
+
- lib/html/tree.rb
|
43
|
+
- lib/html/xmltree.rb
|
44
|
+
- lib/html/xpath.rb
|
45
|
+
- README
|
46
|
+
- test/tc_html-element.rb
|
47
|
+
- test/tc_html-tree.rb
|
48
|
+
- test/tc_stacking-parser.rb
|
49
|
+
- test/tc_xpath.rb
|
50
|
+
- test/tc_source-parser.rb
|
51
|
+
test_files:
|
52
|
+
- test/suite.rb
|
53
|
+
rdoc_options: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
requirements: []
|
58
|
+
dependencies: []
|