XDDCrawler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88afa97837d793c6195182fda0fa8428f4bee2d3
4
+ data.tar.gz: 84e83871931f9662a816aa0be88f8eb641cb2ef7
5
+ SHA512:
6
+ metadata.gz: 5e36bc039887b0538019a0307fe95c79c1af9ea3d81a6ac8dcdd1824f7e06915aaa615ce6823a81e43dc6ef847974e57bb1ddc9fbd4a690563473e5aab8f047e
7
+ data.tar.gz: 0d323226a64d943b9b0b27a95be595026c24cfc2e014abdef410ab9937596def5ec9e4c0e32b897ace0ae1eda19242eb0fe6b88316b42b6ffcc2fee6ac2d3a4d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in XDDCrawler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yukai Huang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # XDDCrawler
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'XDDCrawler'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install XDDCrawler
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/XDDCrawler/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'XDDCrawler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "XDDCrawler"
8
+ spec.version = XDDCrawler::VERSION
9
+ spec.authors = ["Yukai Huang"]
10
+ spec.email = ["yukaihuang1993@hotmail.com"]
11
+ spec.summary = %q{a simple wrapper for nokogiri/rest-client}
12
+ spec.description = %q{a simple wrapper for nokogiri/rest-client, aim to make capybara like dsl}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "nokogiri", '~> 1.6', '>= 1.6.6.2'
25
+ spec.add_dependency "rest-client", '~> 1.8', '>= 1.8.0'
26
+ end
@@ -0,0 +1,3 @@
1
+ module XDDCrawler
2
+ VERSION = "0.0.1"
3
+ end
data/lib/XDDCrawler.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "XDDCrawler/version"
2
+ require 'nokogiri'
3
+ require 'rest-client'
4
+
5
+ module XDDCrawler
6
+ module ASPEssential
7
+ attr_reader :current_url
8
+
9
+ def initialize opts = {}
10
+ end
11
+
12
+ def visit url
13
+ handle_response RestClient.get url
14
+ @current_url = url
15
+ end
16
+
17
+ def submit submit_name=nil, form_data={}
18
+ submit_selector = "input[type=\"submit\"][value=\"#{submit_name}\"]"
19
+
20
+ if submit_name.nil?
21
+ post_hash = get_view_state.merge(form_data)
22
+ else
23
+ post_hash = Hash[@doc.css(submit_selector).map{|node| [node[:name], node[:value]]}].merge(get_view_state).merge(form_data)
24
+ end
25
+
26
+ post_path = @doc.css(submit_selector).xpath('ancestor::form[1]//@action')[0].value
27
+
28
+ uri = URI.parse(@current_url)
29
+ if post_path[0] == '/'
30
+ post_path = "#{uri.scheme}://#{uri.host}/"
31
+ else
32
+ post_path = URI.join("#{File.dirname(uri.to_s)}/", post_path).to_s
33
+ end
34
+
35
+ post post_path, post_hash
36
+ end
37
+
38
+ def post url, opt = {}
39
+ handle_response RestClient.post url, opt.merge({cookies: @cookies})
40
+ @current_url = url
41
+ end
42
+
43
+ def get_view_state
44
+ Hash[@doc.css('input[type="hidden"]').map {|d| [d[:name], d[:value]]}]
45
+ end
46
+
47
+ private
48
+ def handle_response response
49
+ @doc = Nokogiri::HTML response.force_encoding('utf-8')
50
+ @cookies ||= response.cookies
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: XDDCrawler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yukai Huang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-25 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.6.6.2
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.6'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.6.6.2
61
+ - !ruby/object:Gem::Dependency
62
+ name: rest-client
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.8'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.8.0
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.8'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.8.0
81
+ description: a simple wrapper for nokogiri/rest-client, aim to make capybara like
82
+ dsl
83
+ email:
84
+ - yukaihuang1993@hotmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - XDDCrawler.gemspec
95
+ - lib/XDDCrawler.rb
96
+ - lib/XDDCrawler/version.rb
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: a simple wrapper for nokogiri/rest-client
121
+ test_files: []