mechanize 2.14.1 → 2.14.2

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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/lib/mechanize/directory_saver.rb +2 -1
  4. data/lib/mechanize/file_saver.rb +2 -0
  5. data/lib/mechanize/parser.rb +33 -3
  6. data/lib/mechanize/test_case.rb +2 -9
  7. data/lib/mechanize/version.rb +1 -1
  8. metadata +3 -172
  9. data/.autotest +0 -6
  10. data/.github/dependabot.yml +0 -11
  11. data/.github/workflows/ci.yml +0 -43
  12. data/.github/workflows/upstream.yml +0 -51
  13. data/.gitignore +0 -15
  14. data/.yardopts +0 -8
  15. data/Gemfile +0 -12
  16. data/Rakefile +0 -56
  17. data/examples/flickr_upload.rb +0 -22
  18. data/examples/latest_user_agents.rb +0 -100
  19. data/examples/mech-dump.rb +0 -5
  20. data/examples/proxy_req.rb +0 -7
  21. data/examples/rubygems.rb +0 -23
  22. data/examples/spider.rb +0 -22
  23. data/examples/wikipedia_links_to_philosophy.rb +0 -158
  24. data/mechanize.gemspec +0 -74
  25. data/test/data/htpasswd +0 -1
  26. data/test/data/server.crt +0 -16
  27. data/test/data/server.csr +0 -12
  28. data/test/data/server.key +0 -15
  29. data/test/data/server.pem +0 -15
  30. data/test/test_mechanize.rb +0 -1382
  31. data/test/test_mechanize_cookie.rb +0 -559
  32. data/test/test_mechanize_cookie_jar.rb +0 -615
  33. data/test/test_mechanize_directory_saver.rb +0 -60
  34. data/test/test_mechanize_download.rb +0 -102
  35. data/test/test_mechanize_element_not_found_error.rb +0 -16
  36. data/test/test_mechanize_file.rb +0 -118
  37. data/test/test_mechanize_file_connection.rb +0 -40
  38. data/test/test_mechanize_file_request.rb +0 -26
  39. data/test/test_mechanize_file_response.rb +0 -48
  40. data/test/test_mechanize_file_saver.rb +0 -22
  41. data/test/test_mechanize_form.rb +0 -1025
  42. data/test/test_mechanize_form_check_box.rb +0 -49
  43. data/test/test_mechanize_form_encoding.rb +0 -110
  44. data/test/test_mechanize_form_field.rb +0 -78
  45. data/test/test_mechanize_form_file_upload.rb +0 -21
  46. data/test/test_mechanize_form_image_button.rb +0 -13
  47. data/test/test_mechanize_form_keygen.rb +0 -34
  48. data/test/test_mechanize_form_multi_select_list.rb +0 -98
  49. data/test/test_mechanize_form_option.rb +0 -60
  50. data/test/test_mechanize_form_radio_button.rb +0 -96
  51. data/test/test_mechanize_form_select_list.rb +0 -81
  52. data/test/test_mechanize_form_textarea.rb +0 -53
  53. data/test/test_mechanize_headers.rb +0 -36
  54. data/test/test_mechanize_history.rb +0 -104
  55. data/test/test_mechanize_http_agent.rb +0 -2145
  56. data/test/test_mechanize_http_auth_challenge.rb +0 -64
  57. data/test/test_mechanize_http_auth_realm.rb +0 -56
  58. data/test/test_mechanize_http_auth_store.rb +0 -233
  59. data/test/test_mechanize_http_content_disposition_parser.rb +0 -167
  60. data/test/test_mechanize_http_www_authenticate_parser.rb +0 -204
  61. data/test/test_mechanize_image.rb +0 -9
  62. data/test/test_mechanize_link.rb +0 -171
  63. data/test/test_mechanize_page.rb +0 -295
  64. data/test/test_mechanize_page_encoding.rb +0 -215
  65. data/test/test_mechanize_page_frame.rb +0 -17
  66. data/test/test_mechanize_page_image.rb +0 -191
  67. data/test/test_mechanize_page_link.rb +0 -377
  68. data/test/test_mechanize_page_meta_refresh.rb +0 -151
  69. data/test/test_mechanize_parser.rb +0 -316
  70. data/test/test_mechanize_pluggable_parser.rb +0 -68
  71. data/test/test_mechanize_redirect_limit_reached_error.rb +0 -25
  72. data/test/test_mechanize_redirect_not_get_or_head_error.rb +0 -15
  73. data/test/test_mechanize_response_read_error.rb +0 -29
  74. data/test/test_mechanize_subclass.rb +0 -23
  75. data/test/test_mechanize_util.rb +0 -144
  76. data/test/test_mechanize_xml_file.rb +0 -30
  77. data/test/test_multi_select.rb +0 -120
@@ -1,5 +0,0 @@
1
- require 'rubygems'
2
- require 'mechanize'
3
-
4
- agent = Mechanize.new
5
- puts agent.get(ARGV[0]).inspect
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'mechanize'
3
-
4
- agent = Mechanize.new
5
- agent.set_proxy('localhost', '8000')
6
- page = agent.get(ARGV[0])
7
- puts page.body
data/examples/rubygems.rb DELETED
@@ -1,23 +0,0 @@
1
- # This example logs a user in to rubygems and prints out the body of the
2
- # page after logging the user in.
3
- require 'rubygems'
4
- require 'mechanize'
5
- require 'logger'
6
-
7
- # Create a new mechanize object
8
- mech = Mechanize.new
9
- mech.log = Logger.new $stderr
10
- mech.agent.http.debug_output = $stderr
11
-
12
- # Load the rubygems website
13
- page = mech.get('https://rubygems.org/')
14
- page = mech.click page.link_with(:text => /Sign in/) # Click the login link
15
- form = page.forms[1] # Select the first form
16
- form["session[who]"] = ARGV[0]
17
- form["session[password]"] = ARGV[1]
18
- form["commit"] = "Sign in"
19
-
20
- # Submit the form
21
- page = form.submit form.buttons.first
22
-
23
- puts page.body # Print out the body
data/examples/spider.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'rubygems'
2
- require 'mechanize'
3
-
4
- agent = Mechanize.new
5
- agent.max_history = nil # unlimited history
6
- stack = agent.get(ARGV[0]).links
7
-
8
- while l = stack.pop
9
- next unless l.uri
10
- host = l.uri.host
11
- next unless host.nil? or host == agent.history.first.uri.host
12
- next if agent.visited? l.href
13
-
14
- puts "crawling #{l.uri}"
15
- begin
16
- page = l.click
17
- next unless Mechanize::Page === page
18
- stack.push(*page.links)
19
- rescue Mechanize::ResponseCodeError
20
- end
21
- end
22
-
@@ -1,158 +0,0 @@
1
- require 'mechanize'
2
- require 'tsort'
3
-
4
- ##
5
- # This example implements the alt-text of http://xkcd.com/903/ which states:
6
- #
7
- # Wikipedia trivia: if you take any article, click on the first link in the
8
- # article text not in parentheses or italics, and then repeat, you will
9
- # eventually end up at "Philosophy".
10
-
11
- class WikipediaLinksToPhilosophy
12
-
13
- def initialize
14
- @agent = Mechanize.new
15
- @agent.user_agent_alias = 'Mac Safari' # Wikipedia blocks "mechanize"
16
-
17
- @history = @agent.history
18
-
19
- @wiki_url = URI 'http://en.wikipedia.org'
20
- @search_url = @wiki_url + '/w/index.php'
21
- @random_url = @wiki_url + '/wiki/Special:Random'
22
-
23
- @title = nil
24
- @seen = nil
25
- end
26
-
27
- ##
28
- # Retrieves the title of the current page
29
-
30
- def extract_title
31
- @page.title =~ /(.*) - Wikipedia/
32
-
33
- @title = $1
34
- end
35
-
36
- ##
37
- # Retrieves the initial page. If +query+ is not given a random page is
38
- # chosen
39
-
40
- def fetch_first_page query
41
- if query then
42
- search query
43
- else
44
- random
45
- end
46
- end
47
-
48
- ##
49
- # The search is finished if we've seen the page before or we've reached
50
- # Philosophy
51
-
52
- def finished?
53
- @seen or @title == 'Philosophy'
54
- end
55
-
56
- ##
57
- # Follows the first non-parenthetical, non-italic link in the main body of
58
- # the article.
59
-
60
- def follow_first_link
61
- puts "#{@title} (#{@page.uri})"
62
-
63
- # > p > a rejects italics
64
- links = @page.root.css('.mw-content-ltr p > a[href^="/wiki/"]')
65
-
66
- # reject disambiguation and special pages, images and files
67
- links = links.reject do |link_node|
68
- link_node['href'] =~ %r%/wiki/\w+:|\(disambiguation\)%
69
- end
70
-
71
- links = links.reject do |link_node|
72
- in_parenthetical? link_node
73
- end
74
-
75
- link = links.first
76
-
77
- if link.nil?
78
- puts "Could not parse #{@page.uri}"
79
- exit 1
80
- end
81
-
82
- # convert a Nokogiri HTML element back to a mechanize link
83
- link = Mechanize::Page::Link.new link, @agent, @page
84
-
85
- return if @seen = @agent.visited?(link)
86
-
87
- @page = link.click
88
-
89
- extract_title
90
- end
91
-
92
- ##
93
- # Is +link_node+ in an open parenthetical section?
94
-
95
- def in_parenthetical? link_node
96
- siblings = link_node.parent.children
97
-
98
- seen = false
99
-
100
- before = siblings.reject do |node|
101
- seen or (seen = node == link_node)
102
- end
103
-
104
- preceding_text = before.map { |node| node.text }.join
105
-
106
- open = preceding_text.count '('
107
- close = preceding_text.count ')'
108
-
109
- open > close
110
- end
111
-
112
- ##
113
- # Prints the result of the search
114
-
115
- def print_result
116
- if @seen then
117
- puts "[Loop detected]"
118
- else
119
- puts @title
120
- end
121
- puts
122
- # subtract initial search or Special:Random
123
- puts "After #{@agent.history.length - 1} pages"
124
- end
125
-
126
- ##
127
- # Retrieves a random page from wikipedia
128
-
129
- def random
130
- @page = @agent.get @random_url
131
-
132
- extract_title
133
- end
134
-
135
- ##
136
- # Entry point
137
-
138
- def run query = nil
139
- fetch_first_page query
140
-
141
- follow_first_link until finished?
142
-
143
- print_result
144
- end
145
-
146
- ##
147
- # Searches for +query+ on wikipedia
148
-
149
- def search query
150
- @page = @agent.get @search_url, search: query
151
-
152
- extract_title
153
- end
154
-
155
- end
156
-
157
- WikipediaLinksToPhilosophy.new.run ARGV.shift if $0 == __FILE__
158
-
data/mechanize.gemspec DELETED
@@ -1,74 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
- require_relative 'lib/mechanize/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "mechanize"
7
- spec.version = Mechanize::VERSION
8
- spec.homepage = "https://github.com/sparklemotion/mechanize"
9
- spec.summary = 'The Mechanize library is used for automating interaction with websites'
10
- spec.description =
11
- [
12
- "The Mechanize library is used for automating interaction with websites.",
13
- "Mechanize automatically stores and sends cookies, follows redirects,",
14
- "and can follow links and submit forms. Form fields can be populated and",
15
- "submitted. Mechanize also keeps track of the sites that you have visited as",
16
- "a history.",
17
- ].join("\n")
18
-
19
- spec.authors =
20
- [
21
- 'Eric Hodel',
22
- 'Aaron Patterson',
23
- 'Mike Dalessio',
24
- 'Akinori MUSHA',
25
- 'Lee Jarvis',
26
- ]
27
- spec.email =
28
- [
29
- 'drbrain@segment7.net',
30
- 'aaron.patterson@gmail.com',
31
- 'mike.dalessio@gmail.com',
32
- 'knu@idaemons.org',
33
- 'ljjarvis@gmail.com',
34
- ]
35
-
36
- spec.metadata = {
37
- 'yard.run' => 'yard',
38
- 'bug_tracker_uri' => 'https://github.com/sparklemotion/mechanize/issues',
39
- 'changelog_uri' => 'https://github.com/sparklemotion/mechanize/blob/main/CHANGELOG.md',
40
- 'documentation_uri' => 'https://www.rubydoc.info/gems/mechanize',
41
- 'homepage_uri' => 'https://github.com/sparklemotion/mechanize',
42
- 'source_code_uri' => 'https://github.com/sparklemotion/mechanize'
43
- }
44
-
45
- spec.license = "MIT"
46
-
47
- spec.require_paths = ["lib"]
48
- spec.files = %x(git ls-files).split($/)
49
- spec.test_files = spec.files.grep(%r{^test/})
50
-
51
- spec.extra_rdoc_files += Dir['*.rdoc', '*.md']
52
- spec.rdoc_options = ["--main", "README.md"]
53
-
54
- spec.required_ruby_version = ">= 2.6.0"
55
-
56
- spec.add_runtime_dependency("addressable", "~> 2.8")
57
- spec.add_runtime_dependency("domain_name", ">= 0.5.20190701", "~> 0.5")
58
- spec.add_runtime_dependency("http-cookie", ">= 1.0.3", "~> 1.0")
59
- spec.add_runtime_dependency("mime-types", "~> 3.3")
60
- spec.add_runtime_dependency("net-http-digest_auth", ">= 1.4.1", "~> 1.4")
61
-
62
- # careful! some folks are relying on older versions of net-http-persistent
63
- # - see the socks proxy patch in use at #507 and #464
64
- # - see use of retry_change_requests that was removed at #558
65
- spec.add_runtime_dependency("net-http-persistent", ">= 2.5.2", "< 5.0.dev")
66
-
67
- spec.add_runtime_dependency("nokogiri", ">= 1.11.2", "~> 1.11")
68
- spec.add_runtime_dependency("webrick", "~> 1.7")
69
- spec.add_runtime_dependency("webrobots", "~> 0.1.2")
70
-
71
- spec.add_runtime_dependency("rubyntlm", ">= 0.6.3", "~> 0.6")
72
- spec.add_runtime_dependency("base64") # removed from bundled gems in 3.4, and needed by rubyntlm (which doesn't declare this dependency)
73
- spec.add_runtime_dependency("nkf") # removed from bundled gems in 3.4
74
- end
data/test/data/htpasswd DELETED
@@ -1 +0,0 @@
1
- mech:44E/qORekFV0E
data/test/data/server.crt DELETED
@@ -1,16 +0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UEST-----
2
- MIIB0jCCATsCAQAwgZExCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpXYXNoaW5ndG9u
3
- MRAwDgYDVQQHEwdTZWF0dGxlMRIwEAYDVQQKEwlNZWNoYW5pemUxEjAQBgNVBAsT
4
- CU1lY2hhbml6ZTEOMAwGA1UEAxMFQWFyb24xIzAhBgkqhkiG9w0BCQEWFGFhcm9u
5
- cEBydWJ5Zm9yZ2Uub3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqZ5iO
6
- GOLQc90ibB0dvEKFK+yGMZKmw/Ko6oCDdC1zrJchcohszSnGuS59gLvAmS8groLf
7
- 77rY31fhKtG5dB8GynaOh4z+kcZhl+hCll+zTq7KH/rPeg4S5iWllm7b6j/HssvT
8
- zSJyo1+p/+8LFXrULrY4Tcv3AJK4elDrI8ghrwIDAQABoAAwDQYJKoZIhvcNAQEE
9
- BQADgYEAT7SPe71NQvT2BYGEmbWb7FlSQrPh+rDQMHt/Akb8+r91NLkxZtbD1e/F
10
- iyI9JloPCEwJXxHBl0VVRpFCRuJNN0z0E/G4NUWu6n+ZkihtnmV6uazzAQmD4pTl
11
- SjoiyVLWU+r4Q4yXWXtJ9GR8Attv32fL3PcP+GGLeurXJAn0MNU=
12
- -----END CERTIFICATE REQUEST-----
data/test/data/server.key DELETED
@@ -1,15 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIICXAIBAAKBgQCqZ5iOGOLQc90ibB0dvEKFK+yGMZKmw/Ko6oCDdC1zrJchcohs
3
- zSnGuS59gLvAmS8groLf77rY31fhKtG5dB8GynaOh4z+kcZhl+hCll+zTq7KH/rP
4
- eg4S5iWllm7b6j/HssvTzSJyo1+p/+8LFXrULrY4Tcv3AJK4elDrI8ghrwIDAQAB
5
- AoGAC+iZfLS4hSDTv2gW0NErROtA6E/mk8j12GArAwTHeGIDXc8HQbNEzCJ84UBx
6
- 3o/V/06yzruOL0HMfmvjpDY9RLsH02xZb2F/lruw4MJLu50i/Zu8Sjmb1YPSfCh/
7
- 3+8lREA3Uznlq+wHC3yPxQzMBy5jaEdH4IKxT0Bq8TeF0AECQQDSpL47YpRVRsLn
8
- sS00ndEgQQmT5AJWJJtPpbHk6AA0a+zdNeuDRbdF42zG483YEqU7meZbPKR8QbkK
9
- ZQPEBuevAkEAzxjGcz6NZesmN/NQOtOpylewEs1bdIJyBIBmcnmkimLBtdxd0t34
10
- wUKVHLDSj2aemuAHHwsyn/BNXs6F+obmAQJBALpbkAXAAFW1xefvo3vih8sOXyfd
11
- WIfX2SRNBqbq7otyVFudQaChBDUrsOgBUPLyBAdH8DoV27wm9UuR9RPvu/cCQFRr
12
- WgICXqtMFtE56tuACreD1S9k7MHqpsW0/Y3ujicnKKWUhd5+Q3esR5JhdgOkpkSl
13
- y+FYtDNERpW+BBliwgECQA+Vc7pnxwDIOP8kFumdAUmRmhEZjuwArFcywPzrCUn9
14
- 4/KBOp5wDN7kanBwNGZCZ/eQtkb6thAS8C9pufHD1lw=
15
- -----END RSA PRIVATE KEY-----
data/test/data/server.pem DELETED
@@ -1,15 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIICXAIBAAKBgQCqZ5iOGOLQc90ibB0dvEKFK+yGMZKmw/Ko6oCDdC1zrJchcohs
3
- zSnGuS59gLvAmS8groLf77rY31fhKtG5dB8GynaOh4z+kcZhl+hCll+zTq7KH/rP
4
- eg4S5iWllm7b6j/HssvTzSJyo1+p/+8LFXrULrY4Tcv3AJK4elDrI8ghrwIDAQAB
5
- AoGAC+iZfLS4hSDTv2gW0NErROtA6E/mk8j12GArAwTHeGIDXc8HQbNEzCJ84UBx
6
- 3o/V/06yzruOL0HMfmvjpDY9RLsH02xZb2F/lruw4MJLu50i/Zu8Sjmb1YPSfCh/
7
- 3+8lREA3Uznlq+wHC3yPxQzMBy5jaEdH4IKxT0Bq8TeF0AECQQDSpL47YpRVRsLn
8
- sS00ndEgQQmT5AJWJJtPpbHk6AA0a+zdNeuDRbdF42zG483YEqU7meZbPKR8QbkK
9
- ZQPEBuevAkEAzxjGcz6NZesmN/NQOtOpylewEs1bdIJyBIBmcnmkimLBtdxd0t34
10
- wUKVHLDSj2aemuAHHwsyn/BNXs6F+obmAQJBALpbkAXAAFW1xefvo3vih8sOXyfd
11
- WIfX2SRNBqbq7otyVFudQaChBDUrsOgBUPLyBAdH8DoV27wm9UuR9RPvu/cCQFRr
12
- WgICXqtMFtE56tuACreD1S9k7MHqpsW0/Y3ujicnKKWUhd5+Q3esR5JhdgOkpkSl
13
- y+FYtDNERpW+BBliwgECQA+Vc7pnxwDIOP8kFumdAUmRmhEZjuwArFcywPzrCUn9
14
- 4/KBOp5wDN7kanBwNGZCZ/eQtkb6thAS8C9pufHD1lw=
15
- -----END RSA PRIVATE KEY-----