,

Python – Check List of URLs

# -*- coding: UTF-8 -*-

def main():
    source='/webdev/links-of-urls.txt';
    destination=source+".result"
    check_urls(source, destination)
    print('done!')

def check_urls(source, destination):
    with open(source, 'w') as fout:
        with open(source, 'r') as fin:
            for url in fin:
                pre="ERR"
                try:
                    data = urllib2.urlopen(url.trim()).read()
                    pre="OK"
                except:
                    print("Failed...")
                fout.write(pre+" "+url)


if __name__ == '__main__':
    main()

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *