Last active
August 29, 2015 14:11
-
-
Save akirayu101/e13cfaa1d588cd5c3180 to your computer and use it in GitHub Desktop.
test gevent simple 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
__author__ = 'hzyuxin' | |
import requests | |
from gevent import monkey | |
monkey.patch_all() | |
import gevent | |
main_url = 'http://www.cellmap.cn/cellmap_gsm2gps_api.aspx' | |
def job(lac, cell): | |
r = requests.get(main_url, params = {'lac':lac, 'cell':cell}) | |
print r.url | |
print r.text | |
def param_generator(): | |
for x in xrange(0, 65536): | |
for y in xrange(0, 65536): | |
yield x, y | |
def main_process(thread_num, timeout = 1): | |
jobs = [] | |
for x, y in param_generator(): | |
g = gevent.spawn(job, x, y) | |
jobs.append(g) | |
if len(jobs) == 100: | |
gevent.joinall(jobs, timeout = timeout) | |
jobs = [] | |
main_process(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment