Last active
August 29, 2015 13:58
-
-
Save sturgle/9975668 to your computer and use it in GitHub Desktop.
Get Ed2k links from a web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
from string import replace,find,lower | |
from htmllib import HTMLParser | |
from urllib import urlretrieve, urlopen | |
from urlparse import urlparse,urljoin | |
from formatter import DumbWriter,AbstractFormatter | |
from cStringIO import StringIO | |
from codecs import open | |
import re | |
def main(): | |
if len(argv) > 1: | |
url = argv[1] | |
else: | |
try: | |
url = raw_input("Enter starting URL:") | |
except (KeyboardInterrupt,EOFError): | |
url = "" | |
sock = urlopen(url) | |
content = sock.read() | |
sock.close | |
parser = HTMLParser(AbstractFormatter(DumbWriter(StringIO()))) | |
parser.feed(content) | |
parser.close() | |
links = parser.anchorlist | |
if len(links) != 0: | |
file_object = open('ed2k.txt', 'w', 'utf-8') | |
for eachLink in links: | |
if eachLink.find('ed2k') != -1: | |
print eachLink | |
file_object.write('%s\r\n' % eachLink) | |
file_object.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment