Skip to content

Instantly share code, notes, and snippets.

@bongkook
Created March 9, 2014 12:28
Show Gist options
  • Save bongkook/9447046 to your computer and use it in GitHub Desktop.
Save bongkook/9447046 to your computer and use it in GitHub Desktop.
Reading the file stored in the HTML
# -*- coding: utf-8 -*-
import urllib2
import sys
def savefile(contents, filename):
f = open(filename, 'w')
f.write(contents)
f.close()
def gethtml(url):
response = urllib2.urlopen(url)
return response.read()
def main(argv):
if len(argv) != 3:
print 'Usage: gethtml.py <url> <savefile>'
return 1
url = argv[1]
filename = argv[2]
html = gethtml(url)
savefile(html, filename)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment