2010-09-02 41 views

回答

0

rsz=8參數添加到此google search demonstration code, 然後使用start=...參數來控制您接收的哪組結果。

這一點,例如,給你50個結果:

import urllib 
import json 
import sys 
import itertools 

def hits(astr): 
    for start in itertools.count(): 
     query = urllib.urlencode({'q':astr, 'rsz': 8, 'start': start*8}) 
     url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s'%(query) 
     search_results = urllib.urlopen(url) 
     results = json.loads(search_results.read()) 
     data = results['responseData'] 
     if data: 
      hits = data['results'] 
      for h in hits: 
       yield h['url'] 
     else: 
      raise StopIteration 


def showmore(astr,num): 
    for i,h in enumerate(itertools.islice(hits(astr),num)): 
     print('{i}: {h}'.format(i=i,h=h)) 

if __name__=='__main__': 
    showmore(sys.argv[1],50) 
+0

問題是,據我瞭解,如何讓更多的* *超過8所導致一個查詢。 – dpq 2010-09-02 10:59:28

+0

哎呀,我誤解了這個問題......這篇文章會在30秒內自毀... – unutbu 2010-09-02 11:00:35

+0

另一方面,問題不是太難修復... – unutbu 2010-09-02 11:09:57

相關問題