虽然这很可能会破坏Google的TOS,但您可以轻松地抓取自动填充数据:
import requests import json def autocomplete(query, depth=1, lang='en'): if depth == 0: return response = requests.get('https://clients1.google.com/complete/search', params={ 'client': 'hp', 'hl': lang, 'q': query }).text data = response[response.index('(') + 1:-1] o = json.loads(data) for result in o[1]: suggestion = result[0].replace('<b>', '').replace('</b>', '') yield suggestion if depth > 1: for s in autocomplete(suggestion, depth - 1, lang): yield s
autocomplete('a', depth=2) 为您提供开头的前110个查询 a (有一些重复)。将每个字母刮到2的深度,你应该有大量的合法查询可供选择。
autocomplete('a', depth=2)
a