2015-07-26

PYTHON - How to curl into a file?

(1) Install the pycurl package:
easy_install pycurl


(2) Sample script:

import pycurl
c = pycurl.Curl()
c.setopt(c.USERAGENT, 'Mozilla/5.0 (compatible; pycurl)' )

c.setopt(c.URL, 'http://website.com/page1.html')
with open('target_file_name.html', 'w') as f:
    c.setopt( c.WRITEFUNCTION, f.write )
    c.perform()
f.close()

No comments:

Post a Comment