Michael W. Ryan on Thu, 20 Apr 2000 14:43:37 -0400 (EDT) |
On Thu, 20 Apr 2000, neodem wrote: > not sure if this is a scripting questoin or not. I've accumulated a bunch of > URLs over the course of my internet days and I've got them all in a text > file, listed one per line. There's easily over a hundred. > > I'd like to be able to quickly test them to see if they still exist (ie. > they don't return a 4040 error). Is there a quick way I can do this without > writing a dedicated application? Sure. I know Python can, and I'm pretty sure Perl can, also. Here's a way to do it in Python (you could just type this into an interpreter session): ----- BEGIN CODE ----- import urllib, string for line in open('myfile', 'r').readlines(): line = string.strip(line) try: u = urllib.urlopen(line) except IOError: print 'Bad URL:', line else: u.close() ----- END CODE ----- Note that if you type this directly into an interpreter session, you must enter a blank line (with no spaces) at the end for the blocks to get closed. The file will be processed as soon as you enter that blank line. If you want to make it a little program, just include a hash-bang in the first line with the path to your Python interpreter, i.e. "#! /usr/bin/python". Michael W. Ryan, MCP, MCT | OTAKON 2000 mryan@netaxs.com | Convention of Otaku Generation http://www.netaxs.com/~mryan/ | http://www.otakon.com/ No, I don't hear voices in my head; I'm the one that tells the voices in your head what to say. ______________________________________________________________________ Philadelphia Linux Users Group - http://plug.nothinbut.net Announcements - http://lists.nothinbut.net/mail/listinfo/plug-announce General Discussion - http://lists.nothinbut.net/mail/listinfo/plug
|
|