The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

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

TODO: Pull subtitle into page object
Code
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
{
  "avatar_url": "https://avatars.githubusercontent.com/u/845049?v=4",
  "bio": "I like making things and taking notes. In fact, I spend a lot of time making things _to_ take notes",
  "blog": "https://www.alanwsmith.com/",
  "company": "alanwsmith.com",
  "created_at": "2011-06-12T11:08:56Z",
  "email": null,
  "events_url": "https://api.github.com/users/alanwsmith/events{/privacy}",
  "followers": 41,
  "followers_url": "https://api.github.com/users/alanwsmith/followers",
  "following": 45,
  "following_url": "https://api.github.com/users/alanwsmith/following{/other_user}",
  "gists_url": "https://api.github.com/users/alanwsmith/gists{/gist_id}",
  "gravatar_id": "",
  "hireable": null,
  "html_url": "https://github.com/alanwsmith",
  "id": 845049,
  "location": "the u.s.",
  "login": "alanwsmith",
  "name": "Alan Smith",
  "node_id": "MDQ6VXNlcjg0NTA0OQ==",
  "organizations_url": "https://api.github.com/users/alanwsmith/orgs",
  "public_gists": 16,
  "public_repos": 304,
  "received_events_url": "https://api.github.com/users/alanwsmith/received_events",
  "repos_url": "https://api.github.com/users/alanwsmith/repos",
  "site_admin": false,
  "starred_url": "https://api.github.com/users/alanwsmith/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/alanwsmith/subscriptions",
  "twitter_username": null,
  "type": "User",
  "updated_at": "2023-10-22T18:25:07Z",
  "url": "https://api.github.com/users/alanwsmith"
}

Pull the page directly as text

code_start_default_section code_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

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

Pull JSON from a url into a python variable with `requests``


-- code
-- 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/

{
  "avatar_url": "https://avatars.githubusercontent.com/u/845049?v=4",
  "bio": "I like making things and taking notes. In fact, I spend a lot of time making things _to_ take notes",
  "blog": "https://www.alanwsmith.com/",
  "company": "alanwsmith.com",
  "created_at": "2011-06-12T11:08:56Z",
  "email": null,
  "events_url": "https://api.github.com/users/alanwsmith/events{/privacy}",
  "followers": 41,
  "followers_url": "https://api.github.com/users/alanwsmith/followers",
  "following": 45,
  "following_url": "https://api.github.com/users/alanwsmith/following{/other_user}",
  "gists_url": "https://api.github.com/users/alanwsmith/gists{/gist_id}",
  "gravatar_id": "",
  "hireable": null,
  "html_url": "https://github.com/alanwsmith",
  "id": 845049,
  "location": "the u.s.",
  "login": "alanwsmith",
  "name": "Alan Smith",
  "node_id": "MDQ6VXNlcjg0NTA0OQ==",
  "organizations_url": "https://api.github.com/users/alanwsmith/orgs",
  "public_gists": 16,
  "public_repos": 304,
  "received_events_url": "https://api.github.com/users/alanwsmith/received_events",
  "repos_url": "https://api.github.com/users/alanwsmith/repos",
  "site_admin": false,
  "starred_url": "https://api.github.com/users/alanwsmith/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/alanwsmith/subscriptions",
  "twitter_username": null,
  "type": "User",
  "updated_at": "2023-10-22T18:25:07Z",
  "url": "https://api.github.com/users/alanwsmith"
}

-- /results

-- p

Pull the page directly as text

-- code/
-- 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)

-- /code

-- categories
-- Python 

-- metadata
-- date: 2021-07-05 19:40:00
-- id: 20eofsza
-- status: published
-- type: post
-- site: aws