Created
November 21, 2014 15:20
-
-
Save j2labs/9f2412b930f8eeed36ef to your computer and use it in GitHub Desktop.
Simple python spider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
### To use, first install gevent and then requests | |
### | |
### $ pip install gevent requests | |
from gevent import monkey; monkey.patch_all() ### gevent first | |
import gevent | |
import json | |
import requests | |
def handler(url): | |
"""Scrapes a single URL""" | |
response = requests.get(url) | |
print '%s: %s' % (response.status_code, url) | |
return response | |
greenlets = [] | |
for url in ['http://google.com', 'http://yahoo.com']: | |
greenlets.append(gevent.spawn(handler, url)) | |
gevent.joinall(greenlets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment