Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Created March 16, 2012 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeinthehole/2049780 to your computer and use it in GitHub Desktop.
Save codeinthehole/2049780 to your computer and use it in GitHub Desktop.
Desired API for a python URL object
import requests
from someurllib import URL
# 1. Build request URL
url = URL(host='maps.google.com')
url.path('/geocoding/xml/')
.param('q', 'Some address string')
.param('sensor', 'False')
.fragment('something')
response = requests.get(str(url))
# 2. Extract info from URL
url = URL.from_string('https://google.com/some/path/here/?q=testing')
print url.path_segment(2) # 'here'
print url.param('q') # 'testing'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment