-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.rb
More file actions
33 lines (33 loc) · 676 Bytes
/
parser.rb
File metadata and controls
33 lines (33 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'nokogiri'
require 'net/http'
require 'net/https'
$site = ARGV[0]
$site_info = URI.parse($site)
$parse = Net::HTTP.new($site_info.host,$site_info.port)
$parse.use_ssl = true
$parse.verify_mode = OpenSSl::SSL::VERIFY_NONE
$data = $parse.get(ARGV[1])
$html = $data.body
$parser = Nokogiri::HTML($html)
$file = ARGV[4]
if $file != nil then
$mkfile = File.new(ARGV[4],'w')
end
$parser.xpath(ARGV[2]).each do |d|
$option = ARGV[3]
if $option == nil then
puts d
if $file != nil then
$mkfile.write(d)
end
end
else
puts d[$option]
if $file != nil then
$mkfile.write(d[$option])
end
end
end
if $file != nil then
puts "the file is saved as #{$file}"
end