GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pyparallelcurl/test.py at master · conradlee/pyparallelcurl Expand file tree/ Copy pathtest.pyMore file actions executable file ·122 lines (105 loc) · 3.2 KB / Copy pathtest.pyFile metadata and controlsexecutable file ·122 lines (105 loc) · 3.2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 #!/usr/bin/env python # A test script for the ParallelCurl class # # This example fetches a 100 different results from Google's search API, with no more # than 10 outstanding at any time. # # By Pete Warden <[email protected]>, freely reusable, see http://petewarden.typepad.com for more import pyparallelcurl import pycurl import urllib import json import sys SEARCH_URL_PREFIX = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&filter=0' # This function gets called back for each request that completes def on_request_done(content, url, ch, search): if content is None: print "Fetch error for "+url return httpcode = ch.getinfo(pycurl.HTTP_CODE); if httpcode != 200: print "Fetch error "+str(httpcode)+" for '"+url+"'" return responseobject = json.loads(content) if 'responseData' not in responseobject or not responseobject['responseData'] or 'results' not in responseobject['responseData']: print "No results found for '"+search+"'" return print "********" print search+":" print "********" allresponseresults = responseobject['responseData']['results'] for responseresult in allresponseresults: title = responseresult['title'] print title # The terms to search for on Google terms_list = [ "John", "Mary", "William", "Anna", "James", "Emma", "George", "Elizabeth", "Charles", "Margaret", "Frank", "Minnie", "Joseph", "Ida", "Henry", "Bertha", "Robert", "Clara", "Thomas", "Alice", "Edward", "Annie", "Harry", "Florence", "Walter", "Bessie", "Arthur", "Grace", "Fred", "Ethel", "Albert", "Sarah", "Samuel", "Ella", "Clarence", "Martha", "Louis", "Nellie", "David", "Mabel", "Joe", "Laura", "Charlie", "Carrie", "Richard", "Cora", "Ernest", "Helen", "Roy", "Maude", "Will", "Lillian", "Andrew", "Gertrude", "Jesse", "Rose", "Oscar", "Edna", "Willie", "Pearl", "Daniel", "Edith", "Benjamin", "Jennie", "Carl", "Hattie", "Sam", "Mattie", "Alfred", "Eva", "Earl", "Julia", "Peter", "Myrtle", "Elmer", "Louise", "Frederick", "Lillie", "Howard", "Jessie", "Lewis", "Frances", "Ralph", "Catherine", "Herbert", "Lula", "Paul", "Lena", "Lee", "Marie", "Tom", "Ada", "Herman", "Josephine", "Martin", "Fanny", "Jacob", "Lucy", "Michael", "Dora" ] if len(sys.argv) > 1: max_requests = sys.argv[1] else: max_requests = 10 curl_options = { pycurl.SSL_VERIFYPEER: False, pycurl.SSL_VERIFYHOST: False, pycurl.USERAGENT: 'Parallel Curl test script', pycurl.FOLLOWLOCATION: True } parallel_curl = pyparallelcurl.ParallelCurl(max_requests, curl_options) for terms in terms_list: search = '"'+terms+' is a"'; search_url = SEARCH_URL_PREFIX+'&'+urllib.urlencode({'q':terms}) parallel_curl.startrequest(search_url, on_request_done, search) # This should be called when you need to wait for the requests to finish. # This will automatically run on destruct of the ParallelCurl object, so the next line is optional. parallel_curl.finishallrequests() print 'max_requests='+str(max_requests) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |