Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get A Web Page And Pull It Into A Variable In Python

Pull JSON from a url into a python variable with [TODO: Code shorthand span ]

python
import requests
import json

url = 'https://raw.githubusercontent.com/alanwsmith/retrograde-data/main/current/mercury.json'
url = 'https://api.github.com/repos/alanwsmith/neopolitan'
url = 'https://api.github.com/users/alanwsmith'
request = requests.get(url)
json_contents = request.json()

output = json.dumps(
            json_contents,
            sort_keys=True, 
            indent=2, 
            default=str
          )

print(output)
results start

Pull the page directly as text

python
#!/usr/bin/env python

import requests

url = 'https://raw.githubusercontent.com/alanwsmith/retrograde-data/main/current/mercury.json'
request = requests.get('https://api.weather.gov/stations/KSGJ/observations')
contents = request.text
print(contents)