Skip to content

Instantly share code, notes, and snippets.

@Ostapp
Created February 14, 2016 20:25
Show Gist options
  • Save Ostapp/14c7461b6f9781d5c9ef to your computer and use it in GitHub Desktop.
Save Ostapp/14c7461b6f9781d5c9ef to your computer and use it in GitHub Desktop.
import codecs
import requests
from utils import write_json
# download a file and save
r = requests.get('http://pylvax.github.io')
if r.ok:
pylvax_html = r.text
with codecs.open('pylvax.html', 'w', encoding='utf8') as f:
f.write(pylvax_html)
# download and parse JSON
url_json = 'http://paste.ee/r/laxjw'
r = requests.get(url_json)
if r.ok:
# save r.text -> str -> json.loads -> data
# json_str = r.text
# json_data = json.loads(json_str)
# requests .json()
json_rdata = r.json()
write_json('cc.json', json_rdata)
import requests
from utils import write_json
r = requests.get('http://paste.ee/r/laxjw')
if r.ok:
write_json('cc.json', r.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment