scrap_kit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/publish_gem.yml +15 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +162 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/scrap_kit.rb +7 -0
- data/lib/scrap_kit/recipe.rb +68 -0
- data/lib/scrap_kit/version.rb +3 -0
- data/scrap_kit.gemspec +36 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 182c6586405b92385ce91f47c4b2be7d0044e3217604458daeb282ec57af1ccc
|
4
|
+
data.tar.gz: 3dc60725859c3ba88a3288704b011443b3fcca985f4e2f3da899341564aaf913
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00c391a020cab3094e11d0ae2d93574b687bc866f81c076769d302b95024b86c179bc67f1cfc3a9e1f143fa416180467af7c2c6ca1608361106954d7b43ec584
|
7
|
+
data.tar.gz: 625fcc5603b3f111083df489e218bd08635beb8aa71c43453061142e59289698165a48fcca82b71c067fd6700b4274c1925cf4a649ae6f23d14740f5f627f097
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- bin/**/*
|
4
|
+
- node_modules/**/*
|
5
|
+
- log/**/*
|
6
|
+
- tmp/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
- db/migrate/*
|
9
|
+
- db/schema.rb
|
10
|
+
DisabledByDefault: true
|
11
|
+
|
12
|
+
Layout/AccessModifierIndentation:
|
13
|
+
EnforcedStyle: indent
|
14
|
+
|
15
|
+
Layout/BlockAlignment:
|
16
|
+
EnforcedStyleAlignWith: either
|
17
|
+
|
18
|
+
Layout/DefEndAlignment:
|
19
|
+
EnforcedStyleAlignWith: start_of_line
|
20
|
+
|
21
|
+
Layout/DotPosition:
|
22
|
+
EnforcedStyle: leading
|
23
|
+
|
24
|
+
Layout/EmptyComment:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Layout/EmptyLineBetweenDefs:
|
28
|
+
Enabled: true
|
29
|
+
NumberOfEmptyLines: 1
|
30
|
+
|
31
|
+
Layout/EmptyLinesAroundBlockBody:
|
32
|
+
EnforcedStyle: no_empty_lines
|
33
|
+
|
34
|
+
Layout/EmptyLinesAroundClassBody:
|
35
|
+
EnforcedStyle: no_empty_lines
|
36
|
+
|
37
|
+
Layout/EmptyLinesAroundModuleBody:
|
38
|
+
EnforcedStyle: no_empty_lines
|
39
|
+
|
40
|
+
Layout/EndAlignment:
|
41
|
+
EnforcedStyleAlignWith: start_of_line
|
42
|
+
|
43
|
+
Layout/ExtraSpacing:
|
44
|
+
AllowForAlignment: true
|
45
|
+
|
46
|
+
Layout/IndentFirstArrayElement:
|
47
|
+
EnforcedStyle: consistent
|
48
|
+
|
49
|
+
Layout/IndentFirstHashElement:
|
50
|
+
EnforcedStyle: consistent
|
51
|
+
|
52
|
+
Layout/IndentationConsistency:
|
53
|
+
EnforcedStyle: normal
|
54
|
+
|
55
|
+
Layout/IndentationWidth:
|
56
|
+
Width: 2
|
57
|
+
|
58
|
+
Layout/SpaceAroundBlockParameters:
|
59
|
+
EnforcedStyleInsidePipes: no_space
|
60
|
+
|
61
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
62
|
+
EnforcedStyle: space
|
63
|
+
|
64
|
+
Layout/SpaceAroundOperators:
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Layout/SpaceBeforeBlockBraces:
|
68
|
+
EnforcedStyle: space
|
69
|
+
|
70
|
+
Layout/SpaceInLambdaLiteral:
|
71
|
+
EnforcedStyle: require_no_space
|
72
|
+
|
73
|
+
Layout/SpaceInsideBlockBraces:
|
74
|
+
EnforcedStyle: space
|
75
|
+
EnforcedStyleForEmptyBraces: no_space
|
76
|
+
|
77
|
+
Layout/SpaceInsideHashLiteralBraces:
|
78
|
+
EnforcedStyle: space
|
79
|
+
EnforcedStyleForEmptyBraces: no_space
|
80
|
+
|
81
|
+
Layout/SpaceInsideReferenceBrackets:
|
82
|
+
EnforcedStyle: no_space
|
83
|
+
|
84
|
+
Layout/SpaceInsideStringInterpolation:
|
85
|
+
EnforcedStyle: no_space
|
86
|
+
|
87
|
+
Layout/Tab:
|
88
|
+
Enabled: true
|
89
|
+
|
90
|
+
Layout/TrailingWhitespace:
|
91
|
+
Enabled: true
|
92
|
+
|
93
|
+
Lint/SafeNavigationChain:
|
94
|
+
Enabled: true
|
95
|
+
|
96
|
+
Lint/ShadowedArgument:
|
97
|
+
Enabled: true
|
98
|
+
|
99
|
+
Lint/UnusedBlockArgument:
|
100
|
+
Enabled: true
|
101
|
+
|
102
|
+
Lint/UnusedMethodArgument:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
Metrics/LineLength:
|
106
|
+
Max: 100
|
107
|
+
IgnoredPatterns: [(\A|\s)#]
|
108
|
+
|
109
|
+
Naming/VariableName:
|
110
|
+
EnforcedStyle: snake_case
|
111
|
+
|
112
|
+
Style/BlockDelimiters:
|
113
|
+
EnforcedStyle: line_count_based
|
114
|
+
|
115
|
+
Style/BracesAroundHashParameters:
|
116
|
+
EnforcedStyle: no_braces
|
117
|
+
|
118
|
+
Style/EmptyElse:
|
119
|
+
EnforcedStyle: both
|
120
|
+
|
121
|
+
Style/EmptyMethod:
|
122
|
+
EnforcedStyle: expanded
|
123
|
+
|
124
|
+
Style/GlobalVars:
|
125
|
+
AllowedVariables: ["$rollout"]
|
126
|
+
|
127
|
+
Style/HashSyntax:
|
128
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
129
|
+
|
130
|
+
Style/MethodDefParentheses:
|
131
|
+
EnforcedStyle: require_parentheses
|
132
|
+
|
133
|
+
Style/NumericLiterals:
|
134
|
+
MinDigits: 5
|
135
|
+
Strict: false
|
136
|
+
|
137
|
+
Style/RedundantReturn:
|
138
|
+
Enabled: true
|
139
|
+
|
140
|
+
Style/Semicolon:
|
141
|
+
Enabled: true
|
142
|
+
|
143
|
+
Style/SingleLineMethods:
|
144
|
+
Enabled: true
|
145
|
+
|
146
|
+
Style/StabbyLambdaParentheses:
|
147
|
+
EnforcedStyle: require_parentheses
|
148
|
+
|
149
|
+
Style/StringLiterals:
|
150
|
+
EnforcedStyle: double_quotes
|
151
|
+
|
152
|
+
Style/StringLiteralsInInterpolation:
|
153
|
+
EnforcedStyle: single_quotes
|
154
|
+
|
155
|
+
Style/TrailingCommaInArguments:
|
156
|
+
EnforcedStyleForMultiline: no_comma
|
157
|
+
|
158
|
+
Style/TrailingCommaInArrayLiteral:
|
159
|
+
EnforcedStyleForMultiline: no_comma
|
160
|
+
|
161
|
+
Style/TrailingCommaInHashLiteral:
|
162
|
+
EnforcedStyleForMultiline: no_comma
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at hpneo@hotmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
scrap_kit (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (6.0.2.1)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
zeitwerk (~> 2.2)
|
15
|
+
childprocess (3.0.0)
|
16
|
+
concurrent-ruby (1.1.5)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
i18n (1.8.2)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
minitest (5.14.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
regexp_parser (1.6.0)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.1)
|
28
|
+
rspec-support (~> 3.9.1)
|
29
|
+
rspec-expectations (3.9.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.2)
|
36
|
+
rubyzip (2.2.0)
|
37
|
+
selenium-webdriver (3.142.7)
|
38
|
+
childprocess (>= 0.5, < 4.0)
|
39
|
+
rubyzip (>= 1.2.2)
|
40
|
+
thread_safe (0.3.6)
|
41
|
+
tzinfo (1.2.6)
|
42
|
+
thread_safe (~> 0.1)
|
43
|
+
watir (6.16.5)
|
44
|
+
regexp_parser (~> 1.2)
|
45
|
+
selenium-webdriver (~> 3.6)
|
46
|
+
zeitwerk (2.2.2)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
activesupport (= 6.0.2.1)
|
53
|
+
bundler (~> 2.0)
|
54
|
+
rake (~> 10.0)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
scrap_kit!
|
57
|
+
watir (~> 6.16.5)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 hpneo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# ScrapKit
|
2
|
+
|
3
|
+
ScrapKit automates web scraping and converts the results in plain objects by using configuration objects called _recipes_.
|
4
|
+
|
5
|
+
Each recipe can be loaded as an object or as JSON file, and have the following structure:
|
6
|
+
|
7
|
+
```json
|
8
|
+
{
|
9
|
+
"url": "https://status.heroku.com/",
|
10
|
+
"attributes": {
|
11
|
+
"apps": ".subnav__inner .ember-view:nth-child(1) > .status-summary__description",
|
12
|
+
"data": ".subnav__inner .ember-view:nth-child(2) > .status-summary__description",
|
13
|
+
"tools": ".subnav__inner .ember-view:nth-child(3) > .status-summary__description"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
```
|
17
|
+
|
18
|
+
* `url`: It defines the web page to scrape.
|
19
|
+
* `attributes`: Is an object that maps each attribute name with its corresponding CSS selector.
|
20
|
+
|
21
|
+
`attributes` can have a more complex structure to handle collections. For example:
|
22
|
+
|
23
|
+
```json
|
24
|
+
{
|
25
|
+
"url": "https://hpneo.dev/",
|
26
|
+
"attributes": {
|
27
|
+
"posts": {
|
28
|
+
"selector": ".post-item",
|
29
|
+
"children_attributes": {
|
30
|
+
"title": "h2"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
```
|
36
|
+
|
37
|
+
In this case `attributes` has a `posts` key, which will store the results of a collection, defined by a CSS `selector` and an object of children attributes.
|
38
|
+
|
39
|
+
`children_attributes` is an object that maps each attribute name with its corresponding CSS selector (similar to how `attributes` works in its simpler version).
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'scrap_kit'
|
47
|
+
```
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
|
51
|
+
$ bundle
|
52
|
+
|
53
|
+
Or install it yourself as:
|
54
|
+
|
55
|
+
$ gem install scrap_kit
|
56
|
+
|
57
|
+
## Usage
|
58
|
+
|
59
|
+
`ScrapKit::Recipe.load` can take an object with the recipe, or load a JSON file.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
recipe = ScrapKit::Recipe.load(
|
63
|
+
url: "https://status.heroku.com/",
|
64
|
+
attributes: {
|
65
|
+
apps: ".subnav__inner .status-summary:nth-child(1) > .status-summary__description",
|
66
|
+
data: ".subnav__inner .status-summary:nth-child(2) > .status-summary__description",
|
67
|
+
tools: ".subnav__inner .status-summary:nth-child(3) > .status-summary__description",
|
68
|
+
}
|
69
|
+
)
|
70
|
+
|
71
|
+
output = recipe.run
|
72
|
+
#=> {:apps=>"ok", :data=>"ok", :tools=>"ok"}
|
73
|
+
```
|
74
|
+
|
75
|
+
For more complex structures it's recommended to store the recipe in a JSON file:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
recipe = ScrapKit::Recipe.load("./spec/fixtures/file.json")
|
79
|
+
|
80
|
+
output = recipe.run
|
81
|
+
#=> {:posts=>[{:title=>"APIs de Internacionalización en JavaScript"}, {:title=>"Ejecutando comandos desde Ruby"}, {:title=>"Usando Higher-Order Components"}]}
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hpneo/scrap_kit. 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.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
97
|
+
|
98
|
+
## Code of Conduct
|
99
|
+
|
100
|
+
Everyone interacting in the ScrapKit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hpneo/scrap_kit/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "scrap_kit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/scrap_kit.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "active_support/core_ext/hash"
|
2
|
+
require "watir"
|
3
|
+
|
4
|
+
module ScrapKit
|
5
|
+
class Recipe
|
6
|
+
def initialize(url: nil, steps: [], attributes: {})
|
7
|
+
@url = url
|
8
|
+
@steps = steps
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
output = {}
|
14
|
+
|
15
|
+
browser = Watir::Browser.new(:chrome, headless: true)
|
16
|
+
browser.goto @url
|
17
|
+
|
18
|
+
@steps.each do |step|
|
19
|
+
run_step(browser, step)
|
20
|
+
end
|
21
|
+
|
22
|
+
@attributes.each do |attribute_name, selector|
|
23
|
+
output[attribute_name] = extract_attribute(browser, selector)
|
24
|
+
end
|
25
|
+
|
26
|
+
browser.close
|
27
|
+
browser = nil
|
28
|
+
|
29
|
+
output
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_step(browser, step)
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_attribute(browser_or_element, selector_or_hash)
|
36
|
+
if selector_or_hash.is_a?(String)
|
37
|
+
browser_or_element.element(css: selector_or_hash)&.text_content
|
38
|
+
elsif selector_or_hash.is_a?(Hash)
|
39
|
+
selector = selector_or_hash[:selector]
|
40
|
+
selector_for_children_attributes = selector_or_hash[:children_attributes]
|
41
|
+
|
42
|
+
browser_or_element.elements(css: selector).map do |element|
|
43
|
+
output = {}
|
44
|
+
|
45
|
+
selector_for_children_attributes.each do |child_attribute_name, child_selector|
|
46
|
+
output[child_attribute_name] = extract_attribute(element, child_selector)
|
47
|
+
end
|
48
|
+
|
49
|
+
output
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class << self
|
55
|
+
def load(source)
|
56
|
+
input = if source.is_a?(Hash)
|
57
|
+
source
|
58
|
+
elsif source.is_a?(IO)
|
59
|
+
JSON.parse(source.read)
|
60
|
+
else
|
61
|
+
JSON.parse(File.read(source))
|
62
|
+
end
|
63
|
+
|
64
|
+
new(input.deep_symbolize_keys)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/scrap_kit.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "scrap_kit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "scrap_kit"
|
7
|
+
spec.version = ScrapKit::VERSION
|
8
|
+
spec.authors = ["Gustavo Leon"]
|
9
|
+
spec.email = ["hpneo@hotmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Scrap web sites using recipes.}
|
12
|
+
spec.description = %q{Run JSON-based recipes to scrap web sites.}
|
13
|
+
spec.homepage = "https://hpneo.dev/scrap_kit/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/hpneo/scrap_kit"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/hpneo/scrap_kit/blob/master/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "activesupport", "6.0.2.1"
|
35
|
+
spec.add_development_dependency "watir", "~> 6.16.5"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrap_kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Leon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.0.2.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.0.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: watir
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 6.16.5
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 6.16.5
|
83
|
+
description: Run JSON-based recipes to scrap web sites.
|
84
|
+
email:
|
85
|
+
- hpneo@hotmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/workflows/publish_gem.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- lib/scrap_kit.rb
|
105
|
+
- lib/scrap_kit/recipe.rb
|
106
|
+
- lib/scrap_kit/version.rb
|
107
|
+
- scrap_kit.gemspec
|
108
|
+
homepage: https://hpneo.dev/scrap_kit/
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
allowed_push_host: https://rubygems.org
|
113
|
+
homepage_uri: https://hpneo.dev/scrap_kit/
|
114
|
+
source_code_uri: https://github.com/hpneo/scrap_kit
|
115
|
+
changelog_uri: https://github.com/hpneo/scrap_kit/blob/master/CHANGELOG.md
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.0.3
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Scrap web sites using recipes.
|
135
|
+
test_files: []
|