Dienstag, 23. Dezember 2008

download a page and print out links

webseite runterladen und links ausgeben

Hilfslinks:
http://snippets.dzone.com/posts/show/788
http://www.example-code.com/ruby/rubyhttp.asp


Lösung:


1 #!/usr/bin/ruby
2
3
require 'net/http'
4
5 if ARGV.length >0
6 url=ARGV[0]
7 else
8 p " url file"
9 Process.exit
10 end
11
12 req = Net::HTTP.get_response(URI.parse(url))
13 line=req.body
14
15 lines=line.split(" ")
16
17 lines.each do |l|
18 if l.include?("href=http") or l.include?("href=\"http")
19 v1=l.split("\"")
20 if v1.length>1
21 puts v1[1]
22 else
23 puts v1[0]
24 end
25 end
26
27 end

Keine Kommentare:

Kommentar veröffentlichen