Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

fetch.py

#-*-coding:utf8;-*-
#qpy:3
#qpy:console


import urllib.request
import os
import shutil
import argparse


USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/540.0 (KHTML,like Gecko) Chrome/9.1.0.0 Safari/540.0'


def fetch(url, filename):
request = urllib.request.Request(url)
request.add_header('User-Agent', USER_AGENT)
with urllib.request.urlopen(url) as response, open(filename, 'wb') as out_file:
shutil.copyfileobj(response, out_file)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('url')
parser.add_argument('oufile')
arguments = parser.parse_args()
fetch(arguments.url, parser.outfile)



This post first appeared on Ricky's Python Notes, please read the originial post: here

Share the post

fetch.py

×

Subscribe to Ricky's Python Notes

Get updates delivered right to your inbox!

Thank you for your subscription

×