Невозможно получить результаты поиска Google - PullRequest
0 голосов
/ 22 января 2019

Я использую API пользовательского поиска Google для поиска iphone.

Я получил api_key и идентификатор пользовательской поисковой системы.

Затем я последовал примеру Google.

Однако результаты не возвращаются.

Как получить правильный результат?

Мой код выглядит следующим образом:

import requests
import ast

url = r'https://www.googleapis.com/customsearch/v1?key=my_key&cx=se_id&q=iphone'
response = requests.get(url)
result = ast.literal_eval(response.text)

response.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 - iphone', 'totalResults': '0', 'searchTerms': 'iphone', 'count': 10, 'inputEncoding': 'utf8', 'outputEncoding': 'utf8', 'safe': 'off', 'cx': 'abc'}]}, 'searchInformation': {'searchTime': 0.528123, 'formattedSearchTime': '0.53', 'totalResults': '0', 'formattedTotalResults': '0'}}

response.text

'{\n "kind": "customsearch#search",\n "url": {\n  "type": "application/json",\n  "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"\n },\n "queries": {\n  "request": [\n   {\n    "title": "Google Custom Search - iphone",\n    "totalResults": "0",\n    "searchTerms": "iphone",\n    "count": 10,\n    "inputEncoding": "utf8",\n    "outputEncoding": "utf8",\n    "safe": "off",\n    "cx": "abc"\n   }\n  ]\n },\n "searchInformation": {\n  "searchTime": 0.528123,\n  "formattedSearchTime": "0.53",\n  "totalResults": "0",\n  "formattedTotalResults": "0"\n }\n}\n'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...