Ruby writes a script that scans all URLs of the current page

Source: Internet
Author: User
Tags require

A script that scans all URLs in the current page, written in Ruby, is a good example of learning Ruby's friends.

#scanweb.rb
#用法ruby scanweb.rb www.jb51.net 将当前结果保存在c:\1.txt
require 'net/http'
filename= File.new('c:\1.txt',"w+")
if $*[0]==nil
puts "hehe,没有输入网址"
else
h = Net::HTTP.new($*[0], 80)
resp, data = h.get('/index.html', nil)
if resp.message == "OK"
data.scan(/<a href="(.*?)"/).each do |x|
puts x
filename.puts x
end
end
end
#无聊,有vbs、php、ruby版了,好像ruby比vbs快,与php不相上下。
=begin
修改一下
require 'net/http'
filename= File.new('1.txt',"w+")
if $*[0]==nil
abort "用法示例:ruby #$0 www.sohu.com ,结果放在当前目录1.txt"
end
h = Net::HTTP.new($*[0], 80)
resp, data = h.get('/index.html', nil)
if resp.message == "OK"
data.scan(/<a href="(.*?)"/).each do |x|
puts x
filename.puts x
end
end
=end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.