Sunday, 8 September 2013

Writing contents of remote file to local file with urllib2, open() and file

Writing contents of remote file to local file with urllib2, open() and file

I am trying to fetch some js and css scripts from outter sources and write
their contents to a new file on the local disk. Whenever I try to run this
I get several internal errors from the open function, sometimes I even get
Permission Denied errors when trying to access the files.
Any idea on what I could be doing wrong?
Thanks in advance.
doc = urlopen("https://www.example.com/files/boogers.js")
with open(path.join(local_path, "script.js"), "w+") as file:
for line in doc:
file.write(line)

No comments:

Post a Comment