Skip to content

Instantly share code, notes, and snippets.

@syohex
Created January 18, 2012 14:05
Show Gist options
  • Save syohex/1633144 to your computer and use it in GitHub Desktop.
Save syohex/1633144 to your computer and use it in GitHub Desktop.
Simple Python http client
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
from http import Client, Request
url = ''
if len(sys.argv) > 1:
url = sys.argv[1]
else:
sys.exit(1)
client = Client(agent='My User Agent')
request = Request('GET', url)
res = client.request(request)
if res.is_success:
for src in re.finditer(r'src="([^"]+)"', res.content):
print src.groups(0)[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment