Skip to content

Instantly share code, notes, and snippets.

@kennyledet
Created June 2, 2013 11:34
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 kennyledet/5693375 to your computer and use it in GitHub Desktop.
Save kennyledet/5693375 to your computer and use it in GitHub Desktop.
Scrapes Pypi package list for a random Python module.
import urllib2, re, random
html = urllib2.urlopen('https://pypi.python.org/pypi?%3Aaction=index').read()
r = re.compile(r'/pypi/([-A-Za-z0-9\.]+)/([-A-Za-z0-9\.]+)')
pkgName, pkgVersion = random.choice(re.findall(r, html))
print 'Found random package {} {}, located at https://pypi.python.org/pypi/{}/{}'.format(pkgName, pkgVersion, pkgName, pkgVersion)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment