site_prism-tableish 0.0.1 → 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.
- checksums.yaml +4 -4
- data/README.md +87 -4
- data/lib/site_prism/tableish.rb +10 -1
- data/lib/site_prism/tableish/definition.rb +15 -0
- data/lib/site_prism/tableish/element.rb +26 -0
- data/lib/site_prism/tableish/version.rb +1 -1
- data/site_prism-tableish.gemspec +2 -0
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43956014fa7ce3841366f6ca476c2a2307d53305
|
4
|
+
data.tar.gz: 5a8b7bedc3684cb5ec3e0b5ca14eb2c316f3002e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c8b02cf5d011938f6bf53f874af550c9e04cbeae4d894d9b4f2bf1bc2eb1a97fc09ac5441c2567f2083cb53d0bfedbb73e1773bbfacef26fd34c36135d43f6
|
7
|
+
data.tar.gz: d7f09ddc9899f7357627670e76cc76042b7cd9844480b2e13f85b1830d8ba54c5ecbfa743802bd4f6412a3c8810f165641d48bbebe6be234e13bfa92921c0824
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# SitePrism::Tableish
|
2
2
|
|
3
|
-
|
3
|
+
SitePrism::Tableish extends [SitePrism](https://github.com/natritmeyer/site_prism)
|
4
|
+
making it easer and faster to parse `<table>` elements.
|
4
5
|
|
5
|
-
|
6
|
+
Inspied by [SitePrism::Table](https://github.com/investtools/site_prism-table)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,7 +23,85 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
Example:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'site_prism'
|
30
|
+
require 'capybara/dsl'
|
31
|
+
require 'site_prism/tableish'
|
32
|
+
require 'selenium-webdriver'
|
33
|
+
require 'pp'
|
34
|
+
|
35
|
+
Capybara.default_driver = :selenium
|
36
|
+
|
37
|
+
class W3SchoolsTablesPage < SitePrism::Page
|
38
|
+
extend SitePrism::Tableish
|
39
|
+
set_url 'http://www.w3schools.com/html/html_tables.asp'
|
40
|
+
table :customers, '#customers' do
|
41
|
+
column :company
|
42
|
+
column :contact
|
43
|
+
column :country
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
page = W3SchoolsTablesPage.new
|
48
|
+
page.load
|
49
|
+
pp page.customers.rows
|
50
|
+
|
51
|
+
# [{:company=>
|
52
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[2]/td[1]">,
|
53
|
+
# :contact=>
|
54
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[2]/td[2]">,
|
55
|
+
# :country=>
|
56
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[2]/td[3]">},
|
57
|
+
# {:company=>
|
58
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[3]/td[1]">,
|
59
|
+
# :contact=>
|
60
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[3]/td[2]">,
|
61
|
+
# :country=>
|
62
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[3]/td[3]">},
|
63
|
+
# {:company=>
|
64
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[4]/td[1]">,
|
65
|
+
# :contact=>
|
66
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[4]/td[2]">,
|
67
|
+
# :country=>
|
68
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[4]/td[3]">},
|
69
|
+
# {:company=>
|
70
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[5]/td[1]">,
|
71
|
+
# :contact=>
|
72
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[5]/td[2]">,
|
73
|
+
# :country=>
|
74
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[5]/td[3]">},
|
75
|
+
# {:company=>
|
76
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[6]/td[1]">,
|
77
|
+
# :contact=>
|
78
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[6]/td[2]">,
|
79
|
+
# :country=>
|
80
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[6]/td[3]">},
|
81
|
+
# {:company=>
|
82
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[7]/td[1]">,
|
83
|
+
# :contact=>
|
84
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[7]/td[2]">,
|
85
|
+
# :country=>
|
86
|
+
# #<Capybara::Node::Element tag="td" path="/html/body/div[6]/div[1]/div[1]/div[3]/div/table/tbody/tr[7]/td[3]">}]
|
87
|
+
|
88
|
+
pp page.customers.rows.map{|row| row.map{|k, v| [k, v.text.strip]}.to_h }
|
89
|
+
|
90
|
+
# [{:company=>"Alfreds Futterkiste",
|
91
|
+
# :contact=>"MARIA ANDERS",
|
92
|
+
# :country=>"Germany"},
|
93
|
+
# {:company=>"Centro comercial Moctezuma",
|
94
|
+
# :contact=>"FRANCISCO CHANG",
|
95
|
+
# :country=>"Mexico"},
|
96
|
+
# {:company=>"Ernst Handel", :contact=>"ROLAND MENDEL", :country=>"Austria"},
|
97
|
+
# {:company=>"Island Trading", :contact=>"HELEN BENNETT", :country=>"UK"},
|
98
|
+
# {:company=>"Laughing Bacchus Winecellars",
|
99
|
+
# :contact=>"YOSHI TANNAMURI",
|
100
|
+
# :country=>"Canada"},
|
101
|
+
# {:company=>"Magazzini Alimentari Riuniti",
|
102
|
+
# :contact=>"GIOVANNI ROVELLI",
|
103
|
+
# :country=>"Italy"}]
|
104
|
+
```
|
26
105
|
|
27
106
|
## Development
|
28
107
|
|
@@ -32,5 +111,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
111
|
|
33
112
|
## Contributing
|
34
113
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fkshom/site_prism-tableish. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
115
|
+
|
116
|
+
|
117
|
+
## License
|
36
118
|
|
119
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/site_prism/tableish.rb
CHANGED
@@ -2,6 +2,15 @@ require "site_prism/tableish/version"
|
|
2
2
|
|
3
3
|
module SitePrism
|
4
4
|
module Tableish
|
5
|
-
|
5
|
+
|
6
|
+
autoload :Element, 'site_prism/tableish/element'
|
7
|
+
autoload :Definition, 'site_prism/tableish/definition'
|
8
|
+
|
9
|
+
def table(table_name, *args, &block)
|
10
|
+
definition = Definition.new(&block)
|
11
|
+
define_method table_name do |*runtime_args, &element_block|
|
12
|
+
Element.new(page.find(*args), definition)
|
13
|
+
end
|
14
|
+
end
|
6
15
|
end
|
7
16
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SitePrism
|
2
|
+
module Tableish
|
3
|
+
class Element
|
4
|
+
include Capybara::DSL
|
5
|
+
def initialize(root_element, definition)
|
6
|
+
@root_element = root_element
|
7
|
+
@definition = definition
|
8
|
+
end
|
9
|
+
|
10
|
+
def rows
|
11
|
+
[].tap do |result|
|
12
|
+
Capybara.within(@root_element){
|
13
|
+
all(:xpath, ".//tbody/tr | .//body/tr").each do |row_in|
|
14
|
+
row_out = {}
|
15
|
+
row_in.all(:xpath, "td").each_with_index do |cell, i|
|
16
|
+
name, options = @definition.columns[i]
|
17
|
+
row_out[name] = cell
|
18
|
+
end
|
19
|
+
result << row_out unless row_out.empty?
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/site_prism-tableish.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.14"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "selenium-webdriver"
|
28
|
+
spec.add_dependency "site_prism"
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism-tableish
|
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
|
- Shoma FUKUDA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: selenium-webdriver
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: site_prism
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Table scraping for SitePrism
|
56
84
|
email:
|
57
85
|
- fkshom@gmail.com
|
@@ -68,6 +96,8 @@ files:
|
|
68
96
|
- bin/console
|
69
97
|
- bin/setup
|
70
98
|
- lib/site_prism/tableish.rb
|
99
|
+
- lib/site_prism/tableish/definition.rb
|
100
|
+
- lib/site_prism/tableish/element.rb
|
71
101
|
- lib/site_prism/tableish/version.rb
|
72
102
|
- site_prism-tableish.gemspec
|
73
103
|
homepage: https://github.com/fkshom/site_prism-tableish
|