#### klinks v0.2beta # coded by viper - viper@kuht.it - www.kuht.it # released under the GNU GPL License - www.gpl.org # This software scans for a given web page for links that point to files of a given type (by extension) # and puts the resulting links in a html file, sorted in a table. #### ## initialization from HTMLParser import HTMLParser import urlparse,urllib,sys,os,os.path links = [] ## program core def motore(): print " - Fetching " + inpage + "..." try: GetLinks().feed(urllib.urlopen(inpage).read()) except IOError: print "Cannot Get page. Maybe you misspelled it ? Exiting..." sys.exit(0) if len(links) == 0: print "No links to *." + extension + " Files found in " + inpage sys.exit(0) else: pass print " - Opening " + outpage + " output file..." outfile = open(outpage,'w') print " - Building output page and links table..." writeheader(outfile) buildtable(links,outfile) writefooter(outfile) outfile.close() print " - Done... check out " + outpage + " and press Enter to exit. " raw_input("") ## python html parser & table generation class GetLinks(HTMLParser): def handle_starttag(self, tag, attrs): if tag == 'a': if attrs[0][0] == 'href': if attrs[0][1].find('.'+extension) != -1: if attrs[0][1].find('http://') != -1: makeabslink(attrs[0][1]) else: makerellink(inpage,attrs[0][1]) else: pass else: pass else: pass def makeabslink(url): links.append(url) def makerellink(baseurl,url): links.append(urlparse.urljoin(baseurl,url)) ## home-made html generator def writeheader(htmlfile): htmlfile.write("\n") htmlfile.write("
| %d | \n" %('5%',n+1)) htmlfile.write("\n" %('95%')) htmlfile.write(" %s \n" %(array[n],array[n])) htmlfile.write(" | \n") htmlfile.write("