support returning more than 10 results
This commit is contained in:
parent
cb45a25a7c
commit
98ab0e29db
1 changed files with 12 additions and 7 deletions
|
@ -27,13 +27,18 @@ def find(query, max_results=DEFAULT_MAX_RESULTS, timeout=DEFAULT_TIMEOUT):
|
||||||
>>> find("The Matrix site:imdb.com", 1)[0][1]
|
>>> find("The Matrix site:imdb.com", 1)[0][1]
|
||||||
u'http://www.imdb.com/title/tt0133093/'
|
u'http://www.imdb.com/title/tt0133093/'
|
||||||
"""
|
"""
|
||||||
url = 'http://google.com/search?q=%s' % quote_plus(query)
|
|
||||||
data = read_url(url, timeout=timeout)
|
|
||||||
results = []
|
results = []
|
||||||
|
offset = 0
|
||||||
|
while len(results) < max_results:
|
||||||
|
url = 'http://google.com/search?q=%s' % quote_plus(query)
|
||||||
|
if offset:
|
||||||
|
url += '&start=%d' % offset
|
||||||
|
data = read_url(url, timeout=timeout)
|
||||||
data = re.sub('<span class="f">(.*?)</span>', '\\1', data)
|
data = re.sub('<span class="f">(.*?)</span>', '\\1', data)
|
||||||
for a in re.compile('<a href="(htt\S+?)".*?>(.*?)</a>.*?<span class="st">(.*?)<\/span>').findall(data):
|
for a in re.compile('<a href="(htt\S+?)".*?>(.*?)</a>.*?<span class="st">(.*?)<\/span>').findall(data):
|
||||||
results.append((strip_tags(decode_html(a[1])), a[0], strip_tags(decode_html(a[2]))))
|
results.append((strip_tags(decode_html(a[1])), a[0], strip_tags(decode_html(a[2]))))
|
||||||
if len(results) >= max_results:
|
if len(results) >= max_results:
|
||||||
break
|
break
|
||||||
|
offset += 10
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue