如何在Google自定义搜索API中执行trade war "Donald Trump" China
的搜索?
search_word = 'trade war "Donald Trump" China'
url = 'https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}&start=1'.format(key, cx, search_word)
res = requests.get(url)
data = res.json()['items']
此外,res.json()
返回
{'kind': 'customsearch#search', 'url': {'type': 'application/json', 'template': 'https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json'}, 'queries': {'request': [{'title': 'Google Custom Search - trade war "Donald Trump" China', 'totalResults': '0', 'searchTerms': 'trade war "Donald Trump" China', 'count': 10, 'startIndex': 1, 'inputEncoding': 'utf8', 'outputEncoding': 'utf8', 'safe': 'off', 'cx': 'abcdefg'}]}, 'searchInformation': {'searchTime': 0.480801, 'formattedSearchTime': '0.48', 'totalResults': '0', 'formattedTotalResults': '0'}}
正确的方法是什么?
谢谢。