Skip to main content

Google Serper API (谷歌搜索引擎API)

本文档介绍如何使用Google Serper组件进行网络搜索。首先,您需要在serper.dev注册一个免费账户并获取您的API密钥。

import os
import pprint

os.environ["SERPER_API_KEY"] = ""
from langchain.utilities import GoogleSerperAPIWrapper
search = GoogleSerperAPIWrapper()
search.run("奥巴马的名字是什么?")
    '巴拉克·侯赛因·奥巴马二世'

作为自问自答搜索链的一部分

os.environ["OPENAI_API_KEY"] = ""
from langchain.utilities import GoogleSerperAPIWrapper
from langchain.llms.openai import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType

llm = OpenAI(temperature=0)
search = GoogleSerperAPIWrapper()
tools = [
Tool(
name="Intermediate Answer",
func=search.run,
description="在需要进行搜索时很有用",
)
]

self_ask_with_search = initialize_agent(
tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True
)
self_ask_with_search.run(
"当前男子美国公开赛冠军的家乡是哪里?"
)
    

> 进入新的AgentExecutor链...
是的。
追问:谁是当前男子美国公开赛冠军?
中间答案:2022年男子单打冠军Carlos Alcaraz。
追问:Carlos Alcaraz来自哪里?
中间答案:西班牙的El Palmar。
所以最终答案是:El Palmar, Spain

> 完成链。





'El Palmar, Spain'

获取带有元数据的结果 (Obtaining results with metadata)

如果您还希望以结构化的方式获取包括元数据在内的结果。为此,我们将使用包装器的 results 方法。

search = GoogleSerperAPIWrapper()
results = search.results("Apple Inc.")
pprint.pp(results)
    {'searchParameters': {'q': 'Apple Inc.',
'gl': 'us',
'hl': 'en',
'num': 10,
'type': 'search'},
'knowledgeGraph': {'title': 'Apple',
'type': 'Technology company',
'website': 'http://www.apple.com/',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQwGQRv5TjjkycpctY66mOg_e2-npacrmjAb6_jAWhzlzkFE3OTjxyzbA&s=0',
'description': 'Apple Inc. is an American multinational '
'technology company headquartered in '
'Cupertino, California. Apple is the '
"world's largest technology company by "
'revenue, with US$394.3 billion in 2022 '
'revenue. As of March 2023, Apple is the '
"world's biggest...",
'descriptionSource': 'Wikipedia',
'descriptionLink': 'https://en.wikipedia.org/wiki/Apple_Inc.',
'attributes': {'Customer service': '1 (800) 275-2273',
'CEO': 'Tim Cook (Aug 24, 2011–)',
'Headquarters': 'Cupertino, CA',
'Founded': 'April 1, 1976, Los Altos, CA',
'Founders': 'Steve Jobs, Steve Wozniak, '
'Ronald Wayne, and more',
'Products': 'iPhone, iPad, Apple TV, and '
'more'}},
'organic': [{'title': 'Apple',
'link': 'https://www.apple.com/',
'snippet': 'Discover the innovative world of Apple and shop '
'everything iPhone, iPad, Apple Watch, Mac, and Apple '
'TV, plus explore accessories, entertainment, ...',
'sitelinks': [{'title': 'Support',
'link': 'https://support.apple.com/'},
{'title': 'iPhone',
'link': 'https://www.apple.com/iphone/'},
{'title': 'Site Map',
'link': 'https://www.apple.com/sitemap/'},
{'title': 'Business',
'link': 'https://www.apple.com/business/'},
{'title': 'Mac',
'link': 'https://www.apple.com/mac/'},
{'title': 'Watch',
'link': 'https://www.apple.com/watch/'}],
'position': 1},
{'title': 'Apple Inc. - Wikipedia',
'link': 'https://en.wikipedia.org/wiki/Apple_Inc.',
'snippet': 'Apple Inc. is an American multinational technology '
'company headquartered in Cupertino, California. '
"Apple is the world's largest technology company by "
'revenue, ...',
'attributes': {'Products': 'AirPods; Apple Watch; iPad; iPhone; '
'Mac; Full list',
'Founders': 'Steve Jobs; Steve Wozniak; Ronald '
'Wayne; Mike Markkula'},
'sitelinks': [{'title': 'History',
'link': 'https://en.wikipedia.org/wiki/History_of_Apple_Inc.'},
{'title': 'Timeline of Apple Inc. products',
'link': 'https://en.wikipedia.org/wiki/Timeline_of_Apple_Inc._products'},
{'title': 'Litigation involving Apple Inc.',
'link': 'https://en.wikipedia.org/wiki/Litigation_involving_Apple_Inc.'},
{'title': 'Apple Store',
'link': 'https://en.wikipedia.org/wiki/Apple_Store'}],
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRvmB5fT1LjqpZx02UM7IJq0Buoqt0DZs_y0dqwxwSWyP4PIN9FaxuTea0&s',
'position': 2},
{'title': 'Apple Inc. | History, Products, Headquarters, & Facts '
'| Britannica',
'link': 'https://www.britannica.com/topic/Apple-Inc',
'snippet': 'Apple Inc., formerly Apple Computer, Inc., American '
'manufacturer of personal computers, smartphones, '
'tablet computers, computer peripherals, and computer '
'...',
'attributes': {'Related People': 'Steve Jobs Steve Wozniak Jony '
'Ive Tim Cook Angela Ahrendts',
'Date': '1976 - present'},
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS3liELlhrMz3Wpsox29U8jJ3L8qETR0hBWHXbFnwjwQc34zwZvFELst2E&s',
'position': 3},
{'title': 'AAPL: Apple Inc Stock Price Quote - NASDAQ GS - '
'Bloomberg.com',
'link': 'https://www.bloomberg.com/quote/AAPL:US',
'snippet': 'AAPL:USNASDAQ GS. Apple Inc. COMPANY INFO ; Open. '
'170.09 ; Prev Close. 169.59 ; Volume. 48,425,696 ; '
'Market Cap. 2.667T ; Day Range. 167.54170.35.',
'position': 4},
{'title': 'Apple Inc. (AAPL) Company Profile & Facts - Yahoo '
'Finance',
'link': 'https://finance.yahoo.com/quote/AAPL/profile/',
'snippet': 'Apple Inc. designs, manufactures, and markets '
'smartphones, personal computers, tablets, wearables, '
'and accessories worldwide. The company offers '
'iPhone, a line ...',
'position': 5},
{'title': 'Apple Inc. (AAPL) Stock Price, News, Quote & History - '
'Yahoo Finance',
'link': 'https://finance.yahoo.com/quote/AAPL',
'snippet': 'Find the latest Apple Inc. (AAPL) stock quote, '
'history, news and other vital information to help '
'you with your stock trading and investing.',
'position': 6}],
'peopleAlsoAsk': [{'question': 'What does Apple Inc do?',
'snippet': 'Apple Inc. (Apple) designs, manufactures and '
'markets smartphones, personal\n'
'computers, tablets, wearables and accessories '
'and sells a range of related\n'
'services.',
'title': 'AAPL.O - | Stock Price & Latest News - Reuters',
'link': 'https://www.reuters.com/markets/companies/AAPL.O/'},
{'question': 'What is the full form of Apple Inc?',
'snippet': '(formerly Apple Computer Inc.) is an American '
'computer and consumer electronics\n'
'company famous for creating the iPhone, iPad '
'and Macintosh computers.',
'title': 'What is Apple? An products and history overview '
'- TechTarget',
'link': 'https://www.techtarget.com/whatis/definition/Apple'},
{'question': 'What is Apple Inc iPhone?',
'snippet': 'Apple Inc (Apple) designs, manufactures, and '
'markets smartphones, tablets,\n'
'personal computers, and wearable devices. The '
'company also offers software\n'
'applications and related services, '
'accessories, and third-party digital content.\n'
"Apple's product portfolio includes iPhone, "
'iPad, Mac, iPod, Apple Watch, and\n'
'Apple TV.',
'title': 'Apple Inc Company Profile - Apple Inc Overview - '
'GlobalData',
'link': 'https://www.globaldata.com/company-profile/apple-inc/'},
{'question': 'Who runs Apple Inc?',
'snippet': 'Timothy Donald Cook (born November 1, 1960) is '
'an American business executive\n'
'who has been the chief executive officer of '
'Apple Inc. since 2011. Cook\n'
"previously served as the company's chief "
'operating officer under its co-founder\n'
'Steve Jobs. He is the first CEO of any Fortune '
'500 company who is openly gay.',
'title': 'Tim Cook - Wikipedia',
'link': 'https://en.wikipedia.org/wiki/Tim_Cook'}],
'relatedSearches': [{'query': 'Who invented the iPhone'},
{'query': 'Apple iPhone'},
{'query': 'History of Apple company PDF'},
{'query': 'Apple company history'},
{'query': 'Apple company introduction'},
{'query': 'Apple India'},
{'query': 'What does Apple Inc own'},
{'query': 'Apple Inc After Steve'},
{'query': 'Apple Watch'},
{'query': 'Apple App Store'}]}

搜索谷歌图片 (Searching for Google Images)

我们还可以使用这个包装器查询谷歌图片。例如:

search = GoogleSerperAPIWrapper(type="images")
results = search.results("狮子")
pprint.pp(results)
    {'searchParameters': {'q': '狮子',
'gl': 'us',
'hl': 'en',
'num': 10,
'type': 'images'},
'images': [{'title': '狮子 - 维基百科',
'imageUrl': 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Lion_waiting_in_Namibia.jpg/1200px-Lion_waiting_in_Namibia.jpg',
'imageWidth': 1200,
'imageHeight': 900,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRye79ROKwjfb6017jr0iu8Bz2E1KKuHg-A4qINJaspyxkZrkw&s',
'thumbnailWidth': 259,
'thumbnailHeight': 194,
'source': '维基百科',
'domain': 'en.wikipedia.org',
'link': 'https://en.wikipedia.org/wiki/Lion',
'position': 1},
{'title': '狮子 | 特征、栖息地和事实 | 大英百科全书',
'imageUrl': 'https://cdn.britannica.com/55/2155-050-604F5A4A/lion.jpg',
'imageWidth': 754,
'imageHeight': 752,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS3fnDub1GSojI0hJ-ZGS8Tv-hkNNloXh98DOwXZoZ_nUs3GWSd&s',
'thumbnailWidth': 225,
'thumbnailHeight': 224,
'source': '大英百科全书',
'domain': 'www.britannica.com',
'link': 'https://www.britannica.com/animal/lion',
'position': 2},
{'title': '非洲狮子,事实和照片',
'imageUrl': 'https://i.natgeofe.com/n/487a0d69-8202-406f-a6a0-939ed3704693/african-lion.JPG',
'imageWidth': 3072,
'imageHeight': 2043,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTPlTarrtDbyTiEm-VI_PML9VtOTVPuDXJ5ybDf_lN11H2mShk&s',
'thumbnailWidth': 275,
'thumbnailHeight': 183,
'source': '国家地理',
'domain': 'www.nationalgeographic.com',
'link': 'https://www.nationalgeographic.com/animals/mammals/facts/african-lion',
'position': 3},
{'title': '圣路易斯动物园 | 非洲狮子',
'imageUrl': 'https://optimise2.assets-servd.host/maniacal-finch/production/animals/african-lion-01-01.jpg?w=1200&auto=compress%2Cformat&fit=crop&dm=1658933674&s=4b63f926a0f524f2087a8e0613282bdb',
'imageWidth': 1200,
'imageHeight': 1200,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTlewcJ5SwC7yKup6ByaOjTnAFDeoOiMxyJTQaph2W_I3dnks4&s',
'thumbnailWidth': 225,
'thumbnailHeight': 225,
'source': '圣路易斯动物园',
'domain': 'stlzoo.org',
'link': 'https://stlzoo.org/animals/mammals/carnivores/lion',
'position': 4},
{'title': '如何像艺术家一样画一只逼真的狮子 - Studio Wildlife',
'imageUrl': 'https://studiowildlife.com/wp-content/uploads/2021/10/245528858_183911853822648_6669060845725210519_n.jpg',
'imageWidth': 1431,
'imageHeight': 2048,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTmn5HayVj3wqoBDQacnUtzaDPZzYHSLKUlIEcni6VB8w0mVeA&s',
'thumbnailWidth': 188,
'thumbnailHeight': 269,
'source': 'Studio Wildlife',
'domain': 'studiowildlife.com',
'link': 'https://studiowildlife.com/how-to-draw-a-realistic-lion-like-an-artist/',
'position': 5},
{'title': '狮子 | 特征、栖息地和事实 | 大英百科全书',
'imageUrl': 'https://cdn.britannica.com/29/150929-050-547070A1/lion-Kenya-Masai-Mara-National-Reserve.jpg',
'imageWidth': 1600,
'imageHeight': 1085,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSCqaKY_THr0IBZN8c-2VApnnbuvKmnsWjfrwKoWHFR9w3eN5o&s',
'thumbnailWidth': 273,
'thumbnailHeight': 185,
'source': '大英百科全书',
'domain': 'www.britannica.com',
'link': 'https://www.britannica.com/animal/lion',
'position': 6},
{'title': '狮子生活在哪里?关于狮子栖息地和其他有趣事实',
'imageUrl': 'https://www.gannett-cdn.com/-mm-/b2b05a4ab25f4fca0316459e1c7404c537a89702/c=0-0-1365-768/local/-/media/2022/03/16/USATODAY/usatsports/imageForEntry5-ODq.jpg?width=1365&height=768&fit=crop&format=pjpg&auto=webp',
'imageWidth': 1365,
'imageHeight': 768,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTc_4vCHscgvFvYy3PSrtIOE81kNLAfhDK8F3mfOuotL0kUkbs&s',
'thumbnailWidth': 299,
'thumbnailHeight': 168,
'source': '今日美国',
'domain': 'www.usatoday.com',
'link': 'https://www.usatoday.com/story/news/2023/01/08/where-do-lions-live-habitat/10927718002/',
'position': 7},
{'title': '狮子',
'imageUrl': 'https://i.natgeofe.com/k/1d33938b-3d02-4773-91e3-70b113c3b8c7/lion-male-roar_square.jpg',
'imageWidth': 3072,
'imageHeight': 3072,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQqLfnBrBLcTiyTZynHH3FGbBtX2bd1ScwpcuOLnksTyS9-4GM&s',
'thumbnailWidth': 225,
'thumbnailHeight': 225,
'source': '国家地理儿童版',
'domain': 'kids.nationalgeographic.com',
'link': 'https://kids.nationalgeographic.com/animals/mammals/facts/lion',
'position': 8},
{'title': '狮子 | 史密森尼国家动物园',
'imageUrl': 'https://nationalzoo.si.edu/sites/default/files/styles/1400_scale/public/animals/exhibit/africanlion-005.jpg?itok=6wA745g_',
'imageWidth': 1400,
'imageHeight': 845,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSgB3z_D4dMEOWJ7lajJk4XaQSL4DdUvIRj4UXZ0YoE5fGuWuo&s',
'thumbnailWidth': 289,
'thumbnailHeight': 174,
'source': '史密森尼国家动物园',
'domain': 'nationalzoo.si.edu',
'link': 'https://nationalzoo.si.edu/animals/lion',
'position': 9},
{'title': '动物园的新雄狮首次探索栖息地 - 弗吉尼亚动物园',
'imageUrl': 'https://virginiazoo.org/wp-content/uploads/2022/04/ZOO_0056-scaled.jpg',
'imageWidth': 2560,
'imageHeight': 2141,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTDCG7XvXRCwpe_-Vy5mpvrQpVl5q2qwgnDklQhrJpQzObQGz4&s',
'thumbnailWidth': 246,
'thumbnailHeight': 205,
'source': '弗吉尼亚动物园',
'domain': 'virginiazoo.org',
'link': 'https://virginiazoo.org/zoos-new-male-lion-explores-habitat-for-thefirst-time/',
'position': 10}]}

搜索谷歌新闻 (Searching for Google News)

我们还可以使用这个包装器查询谷歌新闻。例如:

search = GoogleSerperAPIWrapper(type="news")
results = search.results("特斯拉公司")
pprint.pp(results)
    {'searchParameters': {'q': '特斯拉公司',
'gl': 'us',
'hl': 'en',
'num': 10,
'type': 'news'},
'news': [{'title': 'ISS建议特斯拉股东反对Robyn Denholm的连任',
'link': 'https://www.reuters.com/business/autos-transportation/iss-recommends-tesla-investors-vote-against-re-election-robyn-denholm-2023-05-04/',
'snippet': '代理投票咨询公司ISS周三建议特斯拉股东反对董事会主席Robyn Denholm的连任,称“存在担忧...',
'date': '5分钟前',
'source': '路透社',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROdETe_GUyp1e8RHNhaRM8Z_vfxCvdfinZwzL1bT1ZGSYaGTeOojIdBoLevA&s',
'position': 1},
{'title': '全球市值最大的公司:特斯拉在四月份跌幅最大',
'link': 'https://www.reuters.com/markets/global-companies-by-market-cap-tesla-fell-most-april-2023-05-02/',
'snippet': '特斯拉公司是四月份市值最大的公司中跌幅最大的,受到季度盈利不佳的打击...',
'date': '1天前',
'source': '路透社',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4u4CP8aOdGyRFH6o4PkXi-_eZDeY96vLSag5gDjhKMYf98YBER2cZPbkStQ&s',
'position': 2},
{'title': '特斯拉希望发动电动车价格战,福特出现了',
'link': 'https://www.bloomberg.com/opinion/articles/2023-05-03/tesla-wanted-an-ev-price-war-ford-showed-up',
'snippet': '这家传统汽车制造商在特斯拉降价竞争对手电动车之后,削减了其Mustang Mach-E型号的成本,预示着竞争将更加激烈...',
'date': '6小时前',
'source': '彭博社',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_3Eo4VI0H-nTeIbYc5DaQn5ep7YrWnmhx6pv8XddFgNF5zRC9gEpHfDq8yQ&s',
'position': 3},
{'title': 'Joby Aviation将获得特斯拉股东Baillie Gifford的投资',
'link': 'https://finance.yahoo.com/news/joby-aviation-investment-tesla-shareholder-204450712.html',
'snippet': '在Joby赢得向美国空军交付最多九架空中出租车的5500万美元合同延期几天后...',
'date': '4小时前',
'source': '雅虎财经',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQO0uVn297LI-xryrPNqJ-apUOulj4ohM-xkN4OfmvMOYh1CPdUEBbYx6hviw&s',
'position': 4},
{'title': '特斯拉恢复美国市场对低价、续航里程更低的Model 3版本的订单',
'link': 'https://finance.yahoo.com/news/tesla-resumes-us-orders-model-045736115.html',
'snippet': '(路透社)-特斯拉公司已经恢复了在美国接受其Model 3长续航车型的订单,该公司的网站显示...',
'date': '19小时前',
'source': '雅虎财经',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTIZetJ62sQefPfbQ9KKDt6iH7Mc0ylT5t_hpgeeuUkHhJuAx2FOJ4ZTRVDFg&s',
'position': 5},
{'title': '特斯拉Model 3长续航后驱版现在在美国市场上有售,续航里程为325英里',
'link': 'https://www.notateslaapp.com/news/1393/tesla-reopens-orders-for-model-3-long-range-after-months-of-unavailability',
'snippet': '特斯拉已经重新开放了Model 3长续航后驱版的订单,由于需求旺盛,该车型在过去几个月一直无法购买...',
'date': '7小时前',
'source': 'Not a Tesla App',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSecrgxZpRj18xIJY-nDHljyP-A4ejEkswa9eq77qhMNrScnVIqe34uql5U4w&s',
'position': 6},
{'title': '特斯拉Cybertruck Alpha原型在弗里蒙特工厂的新照片和视频中被发现',
'link': 'https://www.teslaoracle.com/2023/05/03/tesla-cybertruck-alpha-prototype-interior-and-exterior-spotted-at-the-fremont-factory-in-new-pics-and-videos/',
'snippet': '特斯拉Cybertruck Alpha原型在今年晚些时候投产之前,前往加利福尼亚州弗里蒙特进行另一轮测试(图片...',
'date': '14小时前',
'source': '特斯拉Oracle',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRO7M5ZLQE-Zo4-_5dv9hNAQZ3wSqfvYCuKqzxHG-M6CgLpwPMMG_ssebdcMg&s',
'position': 7},
{'title': '特斯拉在美国的新工厂 - 奥斯汀商业杂志',
'link': 'https://www.bizjournals.com/austin/news/2023/05/02/tesla-leases-building-seattle-area.html',
'snippet': '请查看《普吉特湾商业杂志》关于这家总部位于奥斯汀的公司在太平洋西北地区的房地产规模的报道...',
'date': '22小时前',
'source': '商业杂志',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR9kIEHWz1FcHKDUtGQBS0AjmkqtyuBkQvD8kyIY3kpaPrgYaN7I_H2zoOJsA&s',
'position': 8},
{'title': '特斯拉(TSLA)在积压订单后恢复了Model 3长续航版的订单',
'link': 'https://www.bloomberg.com/news/articles/2023-05-03/tesla-resumes-orders-for-popular-model-3-long-range-at-47-240',
'snippet': '特斯拉公司已经恢复了其起价为47240美元的Model 3长续航版的订单,根据其网站的信息...',
'date': '5小时前',
'source': '彭博社',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTWWIC4VpMTfRvSyqiomODOoLg0xhoBf-Tc1qweKnSuaiTk-Y1wMJZM3jct0w&s',
'position': 9}]}

如果您只想接收最近一小时内发布的新闻文章,可以执行以下操作:

search = GoogleSerperAPIWrapper(type="news", tbs="qdr:h")
results = search.results("特斯拉公司")
pprint.pp(results)
    {'searchParameters': {'q': '特斯拉公司',
'gl': 'us',
'hl': 'en',
'num': 10,
'type': 'news',
'tbs': 'qdr:h'},
'news': [{'title': '俄克拉荷马州州长Stitt看到外国对该州投资的兴趣日益增长',
'link': 'https://www.reuters.com/world/us/oklahoma-gov-stitt-sees-growing-foreign-interest-investments-state-2023-05-04/',
'snippet': '电动汽车制造商特斯拉公司的电池供应商T)表示,正在考虑在俄克拉荷马州建设第三座电池工厂...',
'date': '53分钟前',
'source': '路透社',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSSTcsXeenqmEKdiekvUgAmqIPR4nlAmgjTkBqLpza-lLfjX1CwB84MoNVj0Q&s',
'position': 1},
{'title': 'Ryder在美国推出电动车一站式解决方案',
'link': 'https://www.tyt.com.mx/nota/ryder-lanza-solucion-llave-en-mano-para-vehiculos-electricos-en-eu',
'snippet': 'Ryder System Inc.推出了RyderElectric+ TM作为其新的一站式解决方案... Ryder还预订了特斯拉的半挂车,并继续...',
'date': '56分钟前',
'source': 'Revista Transportes y Turismo',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQJhXTQQtjSUZf9YPM235WQhFU5_d7lEA76zB8DGwZfixcgf1_dhPJyKA1Nbw&s',
'position': 2},
{'title': '“我认为人们可以用9.99亿美元过活,”伯尼·桑德斯告诉美国亿万富翁。',
'link': 'https://thebharatexpressnews.com/i-think-people-can-get-by-with-999-million-bernie-sanders-tells-american-billionaires-heres-how-the-ultra-rich-can-pay-less-income-tax-than-you-legally/',
'snippet': '报告指出,2007年和2011年,亚马逊创始人杰夫·贝索斯“没有支付一分钱的联邦税... 如果您想押注马斯克,请查看特斯拉。',
'date': '11分钟前',
'source': 'THE BHARAT EXPRESS NEWS',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR_X9qqSwVFBBdos2CK5ky5IWIE3aJPCQeRYR9O1Jz4t-MjaEYBuwK7AU3AJQ&s',
'position': 3}]}

一些tbs参数的示例:

qdr:h(过去一小时) qdr:d(过去一天) qdr:w(过去一周) qdr:m(过去一个月) qdr:y(过去一年)

您可以通过添加一个数字来指定中间时间段: qdr:h12(过去12小时) qdr:d3(过去3天) qdr:w2(过去2周) qdr:m6(过去6个月) qdr:m2(过去2年)

有关所有支持的筛选器,请转到谷歌搜索,搜索一些内容,点击“工具”,添加日期筛选器,然后检查URL中的“tbs=”部分。

搜索Google地点 (Searching for Google Places)

我们还可以使用这个包装器查询Google地点。例如:

search = GoogleSerperAPIWrapper(type="places")
results = search.results("Upper East Side的意大利餐厅")
pprint.pp(results)
    {'searchParameters': {'q': 'Upper East Side的意大利餐厅',
'gl': 'us',
'hl': 'en',
'num': 10,
'type': 'places'},
'places': [{'position': 1,
'title': "L'Osteria",
'address': '1219 Lexington Ave',
'latitude': 40.777154599999996,
'longitude': -73.9571363,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNjU7BWEq_aYQANBCbX52Kb0lDpd_lFIx5onw40=w92-h92-n-k-no',
'rating': 4.7,
'ratingCount': 91,
'category': '意大利'},
{'position': 2,
'title': "Tony's Di Napoli",
'address': '1081 3rd Ave',
'latitude': 40.7643567,
'longitude': -73.9642373,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNbNv6jZkJ9nyVi60__8c1DQbe_eEbugRAhIYye=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 2265,
'category': '意大利'},
{'position': 3,
'title': 'Caravaggio',
'address': '23 E 74th St',
'latitude': 40.773412799999996,
'longitude': -73.96473379999999,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipPDGchokDvppoLfmVEo6X_bWd3Fz0HyxIHTEe9V=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 276,
'category': '意大利'},
{'position': 4,
'title': 'Luna Rossa',
'address': '347 E 85th St',
'latitude': 40.776593999999996,
'longitude': -73.950351,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNPCpCPuqPAb1Mv6_fOP7cjb8Wu1rbqbk2sMBlh=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 140,
'category': '意大利'},
{'position': 5,
'title': "Paola's",
'address': '1361 Lexington Ave',
'latitude': 40.7822019,
'longitude': -73.9534096,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipPJr2Vcx-B6K-GNQa4koOTffggTePz8TKRTnWi3=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 344,
'category': '意大利'},
{'position': 6,
'title': 'Come Prima',
'address': '903 Madison Ave',
'latitude': 40.772124999999996,
'longitude': -73.965012,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNrX19G0NVdtDyMovCQ-M-m0c_gLmIxrWDQAAbz=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 176,
'category': '意大利'},
{'position': 7,
'title': 'Botte UES',
'address': '1606 1st Ave.',
'latitude': 40.7750785,
'longitude': -73.9504801,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipPPN5GXxfH3NDacBc0Pt3uGAInd9OChS5isz9RF=w92-h92-n-k-no',
'rating': 4.4,
'ratingCount': 152,
'category': '意大利'},
{'position': 8,
'title': 'Piccola Cucina Uptown',
'address': '106 E 60th St',
'latitude': 40.7632468,
'longitude': -73.9689825,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipPifIgzOCD5SjgzzqBzGkdZCBp0MQsK5k7M7znn=w92-h92-n-k-no',
'rating': 4.6,
'ratingCount': 941,
'category': '意大利'},
{'position': 9,
'title': 'Pinocchio Restaurant',
'address': '300 E 92nd St',
'latitude': 40.781453299999995,
'longitude': -73.9486788,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNtxlIyEEJHtDtFtTR9nB38S8A2VyMu-mVVz72A=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 113,
'category': '意大利'},
{'position': 10,
'title': 'Barbaresco',
'address': '843 Lexington Ave #1',
'latitude': 40.7654332,
'longitude': -73.9656873,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipMb9FbPuXF_r9g5QseOHmReejxSHgSahPMPJ9-8=w92-h92-n-k-no',
'rating': 4.3,
'ratingCount': 122,
'locationHint': '在Touraine内',
'category': '意大利'}]}