Skip to content

Instantly share code, notes, and snippets.

@brookst
Created December 8, 2012 23:31
Show Gist options
  • Save brookst/4242518 to your computer and use it in GitHub Desktop.
Save brookst/4242518 to your computer and use it in GitHub Desktop.
Bittorrent tracker scraper
#!/usr/bin/env python
"""Simple script to scrape a tracker"""
import bencode
import urllib2
SCRAPE_URL = 'http://localhost:6969/scrape'
def scrape(url=SCRAPE_URL):
"""Return dict of scrape results"""
req = urllib2.Request(url)
res = urllib2.urlopen(req)
return bencode.bdecode(res.read())
def print_scrape():
"""Print files with pprint"""
from pprint import pprint
data = scrape()
files = data['files']
for file_hash in files:
pprint(file_hash)
pprint(files[file_hash])
if __name__ == '__main__':
print_scrape()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment