Has anyone ever tried to do something like this? I'm trying to log in to a url and get a listing of all the files on that url. For example, with wget I can fetch the files this way:
this would get the individual file and download it to my local machine. However, I'm trying to automate this script to go out and look at the contents of this directory and do something for each file in there. For example, I want to do something like this:
Has anyone ever tried to do something like this? I'm trying to log in
to a url and get a listing of all the files on that url. For example,
with wget I can fetch the files this way:
this would get the individual file and download it to my local
machine. However, I'm trying to automate this script to go out and
look at the contents of this directory and do something for each file
in there. For example, I want to do something like this:
Has anyone ever tried to do something like this? I'm trying to log in
to a url and get a listing of all the files on that url. For example,
with wget I can fetch the files this way:
this would get the individual file and download it to my local machine.
However, I'm trying to automate this script to go out and look at the
contents of this directory and do something for each file in there. For
example, I want to do something like this:
However, I'm trying to automate this script to go out and look at the contents of this directory and do something for each file in there. For example, I want to do something like this:
However, I'm not sure if there is a simple way to do something like this in Ruby. Anyone encountered this before?
I assume you're talking about the normal automatically-generated directory page, where Apache generates a list of files with links to each file. In which case...
class WebPage
attr_reader :links # URLs of all links on page
# Get a web page from a specified URL
def get(url) @uri = URI.parse(url)
open(url) {|result| @body = result.read }
end
# Parse the web page, extracting links
def parse
if !@body
return
end
tokenizer = HTMLTokenizer.new(@body) @links = Array.new
while tag = tokenizer.getTag('a')
# Normalize to a full URL
url = tag.attr_hash['href']
uri = @uri.merge(url) @links.push(uri.to_s)
end
end
end