【问题标题】:pprint returns nothing in shell ( Google CSE )pprint 在 shell 中不返回任何内容(Google CSE)
【发布时间】:2018-02-02 16:38:26
【问题描述】:

如果这是一个容易回答的问题,请原谅我。我对编程很陌生。我正在关注https://github.com/google/google-api-python-client/blob/master/samples/customsearch/main.py#L21 的示例。

问题:代码在 shell 中运行,但 pprint(res) 没有返回任何内容。不会发生错误。在下面的代码中,我省略了我的 API 密钥和 CX 名称。

我的代码:

from pprint import pprint as pp
from googleapiclient.discovery import build

# initialize API connection with developerKey
def main():
    service = build("customsearch", "v1",
                developerKey="MYKEY")

# define cx and search query and run it
    results = service.cse().list(
        q = 'comptia study notes',
        cx = 'MYCX',
        ).execute()

# print results
    pp(results)

我的目标只是拉出前 10 个搜索结果并将网址保存到一个数组中。

现在,如果我运行 shell 并返回 main(),它会显示所有结果。我知道我的 developerkey 和 cx 设置正确。由于某种原因,它不会打印结果变量。

非常感谢您在这方面的帮助。

【问题讨论】:

    标签: python google-api google-custom-search pprint


    【解决方案1】:

    发布答案以防其他人遇到同样的事情。定义后忘记运行实际函数。

    【讨论】:

      猜你喜欢
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多