Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created November 28, 2014 12:38
Show Gist options
  • Save stefanv/585fc1bb25b1ec30dfab to your computer and use it in GitHub Desktop.
Save stefanv/585fc1bb25b1ec30dfab to your computer and use it in GitHub Desktop.
Search for wheels
from __future__ import print_function
from six.moves import html_parser
from six.moves import urllib
import argparse
url = 'http://wheels.scikit-image.org'
parser = argparse.ArgumentParser(
description='Search for wheels')
parser.add_argument('keyword', nargs='*', help='Search term')
parser.add_argument('--url',
help='URL to scan for wheels (%s by default)' % url)
args = parser.parse_args()
url = args.url or url
class Links(html_parser.HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "a":
href, url = attrs[0]
url = url.replace(url + '/', '')
found = all(word in url for word in args.keyword)
if not args.keyword or found:
print(url)
request = urllib.request.urlopen(url)
data = str(request.read())
Links().feed(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment