mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-23 20:23:59 +00:00
- **Description:** The deprecated initialize_agent functionality is replaced with create_react_agent for the google tools. Also noticed a potential issue with the non-existent "google-drive-search" which was used in the old `google-drive.ipynb`. If this should be a by default available tool, an issue should be opened to modify langchain-community's `load_tools` accordingly. - **Issue:** #29277 - **Dependencies:** No added dependencies - **Twitter handle:** No Twitter account
907 lines
46 KiB
Plaintext
907 lines
46 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "dc23c48e",
|
||
"metadata": {},
|
||
"source": [
|
||
"# Google Serper\n",
|
||
"\n",
|
||
"This notebook goes over how to use the `Google Serper` component to search the web. First you need to sign up for a free account at [serper.dev](https://serper.dev) and get your api key."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ac0b9ce6",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"%pip install --upgrade --quiet langchain-community langchain-openai"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "a8acfb24",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:56:29.336521Z",
|
||
"start_time": "2023-05-04T00:56:29.334173Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
},
|
||
"pycharm": {
|
||
"is_executing": true
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os\n",
|
||
"import pprint\n",
|
||
"\n",
|
||
"os.environ[\"SERPER_API_KEY\"] = \"your-serper-api-key\""
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"id": "54bf5afd",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:07.676293Z",
|
||
"start_time": "2023-05-04T00:54:06.665742Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"from langchain_community.utilities import GoogleSerperAPIWrapper\n",
|
||
"\n",
|
||
"search = GoogleSerperAPIWrapper()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "25ce0225",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:11.399847Z",
|
||
"start_time": "2023-05-04T00:54:09.335597Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"'Barack Hussein Obama II'"
|
||
]
|
||
},
|
||
"execution_count": 3,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"search.run(\"Obama's first name?\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "1f1c6c22",
|
||
"metadata": {},
|
||
"source": [
|
||
"## As part of a Self Ask With Search Agent"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "554358b2",
|
||
"metadata": {},
|
||
"source": [
|
||
"In order to create an agent that uses the Google Serper tool install Langgraph"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "495c301e",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"%pip install --upgrade --quiet langgraph langchain-openai"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "2eb1b45b",
|
||
"metadata": {},
|
||
"source": [
|
||
"and use the `create_react_agent` functionality to initialize a ReAct agent. You will also need to set up your OPEN_API_KEY (visit https://platform.openai.com) in order to access OpenAI's chat models."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "d8da2067",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"from langchain.chat_models import init_chat_model\n",
|
||
"from langchain_community.utilities import GoogleSerperAPIWrapper\n",
|
||
"from langchain_core.tools import Tool\n",
|
||
"from langgraph.prebuilt import create_react_agent\n",
|
||
"\n",
|
||
"os.environ[\"OPENAI_API_KEY\"] = \"[your openai key]\"\n",
|
||
"\n",
|
||
"llm = init_chat_model(\"gpt-4o-mini\", model_provider=\"openai\", temperature=0)\n",
|
||
"search = GoogleSerperAPIWrapper()\n",
|
||
"tools = [\n",
|
||
" Tool(\n",
|
||
" name=\"Intermediate_Answer\",\n",
|
||
" func=search.run,\n",
|
||
" description=\"useful for when you need to ask with search\",\n",
|
||
" )\n",
|
||
"]\n",
|
||
"agent = create_react_agent(llm, tools)\n",
|
||
"\n",
|
||
"events = agent.stream(\n",
|
||
" {\n",
|
||
" \"messages\": [\n",
|
||
" (\"user\", \"What is the hometown of the reigning men's U.S. Open champion?\")\n",
|
||
" ]\n",
|
||
" },\n",
|
||
" stream_mode=\"values\",\n",
|
||
")\n",
|
||
"\n",
|
||
"for event in events:\n",
|
||
" event[\"messages\"][-1].pretty_print()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3aee3682",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Obtaining results with metadata\n",
|
||
"If you would also like to obtain the results in a structured way including metadata. For this we will be using the `results` method of the wrapper."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "073c3fc5",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:22.863413Z",
|
||
"start_time": "2023-05-04T00:54:20.827395Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
},
|
||
"pycharm": {
|
||
"is_executing": true
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'searchParameters': {'q': 'Apple Inc.',\n",
|
||
" 'gl': 'us',\n",
|
||
" 'hl': 'en',\n",
|
||
" 'type': 'search',\n",
|
||
" 'num': 10,\n",
|
||
" 'engine': 'google'},\n",
|
||
" 'knowledgeGraph': {'title': 'Apple',\n",
|
||
" 'type': 'Technology company',\n",
|
||
" 'website': 'http://www.apple.com/',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT5ITHsQzdzkkFWKinRe1Y4FUbC_Vy3R_M&s=0',\n",
|
||
" 'description': 'Apple Inc. is an American multinational '\n",
|
||
" 'corporation and technology company '\n",
|
||
" 'headquartered in Cupertino, California, in '\n",
|
||
" 'Silicon Valley. It is best known for its '\n",
|
||
" 'consumer electronics, software, and '\n",
|
||
" 'services.',\n",
|
||
" 'descriptionSource': 'Wikipedia',\n",
|
||
" 'descriptionLink': 'https://en.wikipedia.org/wiki/Apple_Inc.',\n",
|
||
" 'attributes': {'Customer service': '1 (800) 275-2273',\n",
|
||
" 'Founders': 'Steve Jobs, Steve Wozniak, and '\n",
|
||
" 'Ronald Wayne',\n",
|
||
" 'Founded': 'April 1, 1976, Los Altos, CA',\n",
|
||
" 'Headquarters': 'Cupertino, CA',\n",
|
||
" 'CEO': 'Tim Cook (Aug 24, 2011–)'}},\n",
|
||
" 'organic': [{'title': 'Apple',\n",
|
||
" 'link': 'https://www.apple.com/',\n",
|
||
" 'snippet': 'Discover the innovative world of Apple and shop '\n",
|
||
" 'everything iPhone, iPad, Apple Watch, Mac, and Apple '\n",
|
||
" 'TV, plus explore accessories, entertainment, ...',\n",
|
||
" 'sitelinks': [{'title': 'Career Opportunities',\n",
|
||
" 'link': 'https://www.apple.com/careers/us/'},\n",
|
||
" {'title': 'Support',\n",
|
||
" 'link': 'https://support.apple.com/'},\n",
|
||
" {'title': 'Investor Relations',\n",
|
||
" 'link': 'https://investor.apple.com/investor-relations/default.aspx'},\n",
|
||
" {'title': 'Apple Leadership',\n",
|
||
" 'link': 'https://www.apple.com/leadership/'},\n",
|
||
" {'title': 'Store',\n",
|
||
" 'link': 'https://www.apple.com/store'}],\n",
|
||
" 'position': 1},\n",
|
||
" {'title': 'Apple Inc. - Wikipedia',\n",
|
||
" 'link': 'https://en.wikipedia.org/wiki/Apple_Inc.',\n",
|
||
" 'snippet': 'Apple Inc. is an American multinational corporation '\n",
|
||
" 'and technology company headquartered in Cupertino, '\n",
|
||
" 'California, in Silicon Valley. It is best known for '\n",
|
||
" '...',\n",
|
||
" 'position': 2},\n",
|
||
" {'title': 'Apple Inc. (AAPL) Stock Price Today - WSJ',\n",
|
||
" 'link': 'https://www.wsj.com/market-data/quotes/AAPL',\n",
|
||
" 'snippet': 'Apple Inc. engages in the design, manufacture, and '\n",
|
||
" 'sale of smartphones, personal computers, tablets, '\n",
|
||
" 'wearables and accessories, and other varieties of '\n",
|
||
" 'related ...',\n",
|
||
" 'position': 3},\n",
|
||
" {'title': 'Apple Inc. | History, Products, Headquarters, & Facts '\n",
|
||
" '- Britannica',\n",
|
||
" 'link': 'https://www.britannica.com/money/Apple-Inc',\n",
|
||
" 'snippet': 'American manufacturer of personal computers, '\n",
|
||
" 'smartphones, and tablet computers. Apple was the '\n",
|
||
" 'first successful personal computer company and ...',\n",
|
||
" 'date': '5 days ago',\n",
|
||
" 'position': 4},\n",
|
||
" {'title': 'Apple Inc. (AAPL) Company Profile & Facts - Yahoo '\n",
|
||
" 'Finance',\n",
|
||
" 'link': 'https://finance.yahoo.com/quote/AAPL/profile/',\n",
|
||
" 'snippet': 'See the company profile for Apple Inc. (AAPL) '\n",
|
||
" 'including business summary, industry/sector '\n",
|
||
" 'information, number of employees, business summary, '\n",
|
||
" '...',\n",
|
||
" 'position': 5},\n",
|
||
" {'title': 'AAPL: Apple Inc Stock Price Quote - NASDAQ GS - '\n",
|
||
" 'Bloomberg',\n",
|
||
" 'link': 'https://www.bloomberg.com/quote/AAPL:US',\n",
|
||
" 'snippet': 'Apple Inc. designs, manufactures, and markets '\n",
|
||
" 'smartphones, personal computers, tablets, wearables '\n",
|
||
" 'and accessories, and sells a variety of related '\n",
|
||
" 'accessories.',\n",
|
||
" 'position': 6}],\n",
|
||
" 'images': [{'title': 'Apple Inc. - Wikipedia',\n",
|
||
" 'imageUrl': 'https://upload.wikimedia.org/wikipedia/commons/f/fa/Apple_logo_black.svg',\n",
|
||
" 'link': 'https://en.wikipedia.org/wiki/Apple_Inc.'},\n",
|
||
" {'title': 'Apple Inc. - Wikipedia',\n",
|
||
" 'imageUrl': 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Aerial_view_of_Apple_Park_dllu.jpg/330px-Aerial_view_of_Apple_Park_dllu.jpg',\n",
|
||
" 'link': 'https://en.wikipedia.org/wiki/Apple_Inc.'},\n",
|
||
" {'title': 'Apple',\n",
|
||
" 'imageUrl': 'https://www.apple.com/ac/structured-data/images/open_graph_logo.png?202110180743',\n",
|
||
" 'link': 'https://www.apple.com/'},\n",
|
||
" {'title': 'Apple Store - Find a Store - Apple',\n",
|
||
" 'imageUrl': 'https://rtlimages.apple.com/cmc/dieter/store/16_9/R289.png?resize=672:378&output-format=jpg&output-quality=85&interpolation=progressive-bicubic',\n",
|
||
" 'link': 'https://www.apple.com/retail/'},\n",
|
||
" {'title': 'Apple | LinkedIn',\n",
|
||
" 'imageUrl': 'https://media.licdn.com/dms/image/v2/C560BAQHdAaarsO-eyA/company-logo_200_200/company-logo_200_200/0/1630637844948/apple_logo?e=2147483647&v=beta&t=pOXzU29XHyAnHt2zp2JryxZvMBdKpqxkkbDWtZ_pnEk',\n",
|
||
" 'link': 'https://www.linkedin.com/company/apple'},\n",
|
||
" {'title': 'The Founding of Apple Computer, Inc. - This Month in '\n",
|
||
" 'Business ...',\n",
|
||
" 'imageUrl': 'https://tile.loc.gov/storage-services/service/pnp/highsm/49100/49193r.jpg',\n",
|
||
" 'link': 'https://guides.loc.gov/this-month-in-business-history/april/apple-computer-founded'},\n",
|
||
" {'title': 'Apple Inc. (AAPL) Stock Price, News, Quote & History - '\n",
|
||
" 'Yahoo Finance',\n",
|
||
" 'imageUrl': 'https://s.yimg.com/uu/api/res/1.2/wsqdHHH05iioDnVbAb2WPQ--~B/aD01NzY7dz0xMDI0O2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/Benzinga/8f4e6ec4860c044f97cc63cfdd74b4f2.cf.webp',\n",
|
||
" 'link': 'https://finance.yahoo.com/quote/AAPL/'},\n",
|
||
" {'title': 'Apple Store - Find a Store - Apple',\n",
|
||
" 'imageUrl': 'https://rtlimages.apple.com/cmc/dieter/store/16_9/R219.png?resize=672:378&output-format=jpg&output-quality=85&interpolation=progressive-bicubic',\n",
|
||
" 'link': 'https://www.apple.com/retail/'},\n",
|
||
" {'title': 'Apple Store - Find a Store - Apple',\n",
|
||
" 'imageUrl': 'https://rtlimages.apple.com/cmc/dieter/store/16_9/R420.png?resize=672:378&output-format=jpg&output-quality=85&interpolation=progressive-bicubic',\n",
|
||
" 'link': 'https://www.apple.com/retail/'}],\n",
|
||
" 'peopleAlsoAsk': [{'question': 'What is the Apple Inc?',\n",
|
||
" 'snippet': 'It is best known for its consumer electronics, '\n",
|
||
" 'software, and services. Founded in 1976 as '\n",
|
||
" 'Apple Computer Company by Steve Jobs, Steve '\n",
|
||
" 'Wozniak and Ronald Wayne, the company was '\n",
|
||
" 'incorporated by Jobs and Wozniak as Apple '\n",
|
||
" 'Computer, Inc. the following year. It was '\n",
|
||
" 'renamed Apple Inc.',\n",
|
||
" 'title': 'Apple Inc. - Wikipedia',\n",
|
||
" 'link': 'https://en.wikipedia.org/wiki/Apple_Inc.'},\n",
|
||
" {'question': 'Is Apple an LLC or Inc.?',\n",
|
||
" 'snippet': 'Apple Inc., located at One Apple Park Way, '\n",
|
||
" 'Cupertino, California, for users in the United '\n",
|
||
" 'States, including Puerto Rico.',\n",
|
||
" 'title': 'Legal - Privacy Policy Affiliated Company - '\n",
|
||
" 'Apple',\n",
|
||
" 'link': 'https://www.apple.com/legal/privacy/en-ww/affiliated-company/'}],\n",
|
||
" 'relatedSearches': [{'query': 'apple inc คืออะไร'},\n",
|
||
" {'query': 'Apple Inc full form'},\n",
|
||
" {'query': 'Apple Inc address'},\n",
|
||
" {'query': 'Apple Inc investor relations'},\n",
|
||
" {'query': 'Apple Inc industry'},\n",
|
||
" {'query': 'Apple Inc careers'},\n",
|
||
" {'query': 'Apple Inc Net worth'}],\n",
|
||
" 'credits': 1}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"search = GoogleSerperAPIWrapper()\n",
|
||
"results = search.results(\"Apple Inc.\")\n",
|
||
"pprint.pp(results)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b402c308",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Searching for Google Images\n",
|
||
"We can also query Google Images using this wrapper. For example:"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 7,
|
||
"id": "7fb2b7e2",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:27.879867Z",
|
||
"start_time": "2023-05-04T00:54:26.380022Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'searchParameters': {'q': 'Lion',\n",
|
||
" 'gl': 'us',\n",
|
||
" 'hl': 'en',\n",
|
||
" 'type': 'images',\n",
|
||
" 'num': 10,\n",
|
||
" 'engine': 'google'},\n",
|
||
" 'images': [{'title': 'Lion - Wikipedia',\n",
|
||
" 'imageUrl': 'https://upload.wikimedia.org/wikipedia/commons/a/a6/020_The_lion_king_Snyggve_in_the_Serengeti_National_Park_Photo_by_Giles_Laurent.jpg',\n",
|
||
" 'imageWidth': 5168,\n",
|
||
" 'imageHeight': 3448,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR_HGdbfaRDdKJpWDDdD0AkS58dHashCEbqH9yTMz4j7lQIC6iD&s',\n",
|
||
" 'thumbnailWidth': 275,\n",
|
||
" 'thumbnailHeight': 183,\n",
|
||
" 'source': 'Wikipedia',\n",
|
||
" 'domain': 'en.wikipedia.org',\n",
|
||
" 'link': 'https://en.wikipedia.org/wiki/Lion',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fa%2Fa6%2F020_The_lion_king_Snyggve_in_the_Serengeti_National_Park_Photo_by_Giles_Laurent.jpg&tbnid=iu_QQ3Z8fGxRvM&imgrefurl=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FLion&docid=0P9ZPIi_HU4dMM&w=5168&h=3448&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIAigA',\n",
|
||
" 'position': 1},\n",
|
||
" {'title': 'Lion | Characteristics, Habitat, & Facts | Britannica',\n",
|
||
" 'imageUrl': 'https://cdn.britannica.com/29/150929-050-547070A1/lion-Kenya-Masai-Mara-National-Reserve.jpg',\n",
|
||
" 'imageWidth': 1600,\n",
|
||
" 'imageHeight': 1085,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSCqaKY_THr0IBZN8c-2VApnnbuvKmnsWjfrwKoWHFR9w3eN5o&s',\n",
|
||
" 'thumbnailWidth': 273,\n",
|
||
" 'thumbnailHeight': 185,\n",
|
||
" 'source': 'Britannica',\n",
|
||
" 'domain': 'www.britannica.com',\n",
|
||
" 'link': 'https://www.britannica.com/animal/lion',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fcdn.britannica.com%2F29%2F150929-050-547070A1%2Flion-Kenya-Masai-Mara-National-Reserve.jpg&tbnid=DBk5Qx3rVV587M&imgrefurl=https%3A%2F%2Fwww.britannica.com%2Fanimal%2Flion&docid=Zp2R2-BbubSvqM&w=1600&h=1085&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIAygB',\n",
|
||
" 'position': 2},\n",
|
||
" {'title': 'Lion',\n",
|
||
" 'imageUrl': 'https://i.natgeofe.com/k/1d33938b-3d02-4773-91e3-70b113c3b8c7/lion-male-roar.jpg?wp=1&w=1084.125&h=609',\n",
|
||
" 'imageWidth': 1083,\n",
|
||
" 'imageHeight': 609,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDDPsOQpmuAhyuNY28gdM0msnIfqxIlLi01CudMaojO5w0xmM&s',\n",
|
||
" 'thumbnailWidth': 300,\n",
|
||
" 'thumbnailHeight': 168,\n",
|
||
" 'source': 'National Geographic Kids',\n",
|
||
" 'domain': 'kids.nationalgeographic.com',\n",
|
||
" 'link': 'https://kids.nationalgeographic.com/animals/mammals/facts/lion',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fi.natgeofe.com%2Fk%2F1d33938b-3d02-4773-91e3-70b113c3b8c7%2Flion-male-roar.jpg%3Fwp%3D1%26w%3D1084.125%26h%3D609&tbnid=P9Vzzl57Ow4obM&imgrefurl=https%3A%2F%2Fkids.nationalgeographic.com%2Fanimals%2Fmammals%2Ffacts%2Flion&docid=r48PKzcCogU0oM&w=1083&h=609&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIBCgC',\n",
|
||
" 'position': 3},\n",
|
||
" {'title': 'Lion | Characteristics, Habitat, & Facts | Britannica',\n",
|
||
" 'imageUrl': 'https://cdn.britannica.com/30/150930-120-D3D93F1E/lion-panthea-leo-Namibia.jpg',\n",
|
||
" 'imageWidth': 900,\n",
|
||
" 'imageHeight': 675,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYxxLBZ8F_59YdYFJu6y8Zfhf64kMNbrD94uNF0gj9Wgtr4B2k&s',\n",
|
||
" 'thumbnailWidth': 259,\n",
|
||
" 'thumbnailHeight': 194,\n",
|
||
" 'source': 'Britannica',\n",
|
||
" 'domain': 'www.britannica.com',\n",
|
||
" 'link': 'https://www.britannica.com/animal/lion',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fcdn.britannica.com%2F30%2F150930-120-D3D93F1E%2Flion-panthea-leo-Namibia.jpg&tbnid=gu4-4upZHrFJ5M&imgrefurl=https%3A%2F%2Fwww.britannica.com%2Fanimal%2Flion&docid=Zp2R2-BbubSvqM&w=900&h=675&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIBSgD',\n",
|
||
" 'position': 4},\n",
|
||
" {'title': '6,800+ Lion Walking Stock Photos, Pictures & '\n",
|
||
" 'Royalty-Free Images ...',\n",
|
||
" 'imageUrl': 'https://media.istockphoto.com/id/877369086/photo/lion-panthera-leo-10-years-old-isolated-on-white.jpg?s=612x612&w=0&k=20&c=J__Jx_BX_FN7iehO965TJtPFYUl0A-bwFgIYaK32R3Y=',\n",
|
||
" 'imageWidth': 612,\n",
|
||
" 'imageHeight': 527,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQNXCI7damJui7Vvf6TQi0ixg_kgvbGQcl9L01u4Rx6ZCI7lqyR&s',\n",
|
||
" 'thumbnailWidth': 242,\n",
|
||
" 'thumbnailHeight': 208,\n",
|
||
" 'source': 'iStock',\n",
|
||
" 'domain': 'www.istockphoto.com',\n",
|
||
" 'link': 'https://www.istockphoto.com/photos/lion-walking',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fmedia.istockphoto.com%2Fid%2F877369086%2Fphoto%2Flion-panthera-leo-10-years-old-isolated-on-white.jpg%3Fs%3D612x612%26w%3D0%26k%3D20%26c%3DJ__Jx_BX_FN7iehO965TJtPFYUl0A-bwFgIYaK32R3Y%3D&tbnid=UbVNtrUwB3qvSM&imgrefurl=https%3A%2F%2Fwww.istockphoto.com%2Fphotos%2Flion-walking&docid=VUUNuYLgdvat6M&w=612&h=527&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIBigE',\n",
|
||
" 'creator': 'GlobalP',\n",
|
||
" 'credit': 'Getty Images/iStockphoto',\n",
|
||
" 'position': 5},\n",
|
||
" {'title': 'Free Fierce Lion Roaring Image | Download at StockCake',\n",
|
||
" 'imageUrl': 'https://images.stockcake.com/public/6/d/2/6d2a992e-cf12-460f-a811-c961e124d9a2_large/fierce-lion-roaring-stockcake.jpg',\n",
|
||
" 'imageWidth': 408,\n",
|
||
" 'imageHeight': 728,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDLNUIqFT5oEh7CNtksHhODRWcuCYkwjHI-sLQXaV4rCPbcO8R&s',\n",
|
||
" 'thumbnailWidth': 168,\n",
|
||
" 'thumbnailHeight': 300,\n",
|
||
" 'source': 'StockCake',\n",
|
||
" 'domain': 'stockcake.com',\n",
|
||
" 'link': 'https://stockcake.com/i/fierce-lion-roaring_1358116_1064655',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fimages.stockcake.com%2Fpublic%2F6%2Fd%2F2%2F6d2a992e-cf12-460f-a811-c961e124d9a2_large%2Ffierce-lion-roaring-stockcake.jpg&tbnid=14Bc2UcRYg2vRM&imgrefurl=https%3A%2F%2Fstockcake.com%2Fi%2Ffierce-lion-roaring_1358116_1064655&docid=mIUgDyGFaSvxJM&w=408&h=728&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcIBygF',\n",
|
||
" 'position': 6},\n",
|
||
" {'title': 'Lion | Characteristics, Habitat, & Facts | Britannica',\n",
|
||
" 'imageUrl': 'https://cdn.britannica.com/55/2155-050-604F5A4A/lion.jpg',\n",
|
||
" 'imageWidth': 754,\n",
|
||
" 'imageHeight': 752,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS3fnDub1GSojI0hJ-ZGS8Tv-hkNNloXh98DOwXZoZ_nUs3GWSd&s',\n",
|
||
" 'thumbnailWidth': 225,\n",
|
||
" 'thumbnailHeight': 224,\n",
|
||
" 'source': 'Britannica',\n",
|
||
" 'domain': 'www.britannica.com',\n",
|
||
" 'link': 'https://www.britannica.com/animal/lion',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fcdn.britannica.com%2F55%2F2155-050-604F5A4A%2Flion.jpg&tbnid=IhlRPXpsi9aDnM&imgrefurl=https%3A%2F%2Fwww.britannica.com%2Fanimal%2Flion&docid=Zp2R2-BbubSvqM&w=754&h=752&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcICCgG',\n",
|
||
" 'position': 7},\n",
|
||
" {'title': \"Bringing Nigeria's lion population back from extinction \"\n",
|
||
" '- WildAid',\n",
|
||
" 'imageUrl': 'https://wildaid.org/wp-content/uploads/2022/08/Untitled-design-32-400x335.png',\n",
|
||
" 'imageWidth': 400,\n",
|
||
" 'imageHeight': 335,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTnurDJfi5sllJxVxWFjfyU8nvXqxy3ef2dcxUTNBmLND9aVuQ&s',\n",
|
||
" 'thumbnailWidth': 245,\n",
|
||
" 'thumbnailHeight': 205,\n",
|
||
" 'source': '- WildAid',\n",
|
||
" 'domain': 'wildaid.org',\n",
|
||
" 'link': 'https://wildaid.org/bringing-nigerias-lion-population-back-from-extinction/',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fwildaid.org%2Fwp-content%2Fuploads%2F2022%2F08%2FUntitled-design-32-400x335.png&tbnid=ri5ErxfeVw-rUM&imgrefurl=https%3A%2F%2Fwildaid.org%2Fbringing-nigerias-lion-population-back-from-extinction%2F&docid=IRE1bqPePPGKUM&w=400&h=335&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcICSgH',\n",
|
||
" 'position': 8},\n",
|
||
" {'title': 'Lion',\n",
|
||
" 'imageUrl': 'https://images.photowall.com/products/46596/lion-1.jpg?h=699&q=85',\n",
|
||
" 'imageWidth': 699,\n",
|
||
" 'imageHeight': 699,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTT-SMMS4_tLzeHGP8iK6q1f6VuAfAGKuwvRcKhfAmt6GEutoRZ&s',\n",
|
||
" 'thumbnailWidth': 225,\n",
|
||
" 'thumbnailHeight': 225,\n",
|
||
" 'source': 'Photowall',\n",
|
||
" 'domain': 'www.photowall.com',\n",
|
||
" 'link': 'https://www.photowall.com/us/lion-1-poster',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Fimages.photowall.com%2Fproducts%2F46596%2Flion-1.jpg%3Fh%3D699%26q%3D85&tbnid=Hx0R3srHGe7c6M&imgrefurl=https%3A%2F%2Fwww.photowall.com%2Fus%2Flion-1-poster&docid=svxN-CF1BznYSM&w=699&h=699&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcICigI',\n",
|
||
" 'position': 9},\n",
|
||
" {'title': 'Lion | Species | WWF',\n",
|
||
" 'imageUrl': 'https://files.worldwildlife.org/wwfcmsprod/images/Lion_Kenya/story_full_width/92n0a30duq_Medium_WW2116702.jpg',\n",
|
||
" 'imageWidth': 1000,\n",
|
||
" 'imageHeight': 600,\n",
|
||
" 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQcAAjEbm00R6g4382D54syoBUFN19j80OBd31FAOMwK_S2Pa9d&s',\n",
|
||
" 'thumbnailWidth': 290,\n",
|
||
" 'thumbnailHeight': 174,\n",
|
||
" 'source': 'World Wildlife Fund',\n",
|
||
" 'domain': 'www.worldwildlife.org',\n",
|
||
" 'link': 'https://www.worldwildlife.org/species/lion--19',\n",
|
||
" 'googleUrl': 'https://www.google.com/imgres?imgurl=https%3A%2F%2Ffiles.worldwildlife.org%2Fwwfcmsprod%2Fimages%2FLion_Kenya%2Fstory_full_width%2F92n0a30duq_Medium_WW2116702.jpg&tbnid=N9k7RywguCeZmM&imgrefurl=https%3A%2F%2Fwww.worldwildlife.org%2Fspecies%2Flion--19&docid=RqCpf1UYcQDKxM&w=1000&h=600&ved=0ahUKEwjl5-H3hfmMAxUMvokEHY6wD3gQvFcICygJ',\n",
|
||
" 'copyright': 'Juozas Cernius',\n",
|
||
" 'creator': 'Juozas Cernius www.CERNIUS.com',\n",
|
||
" 'position': 10}],\n",
|
||
" 'credits': 1}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"search = GoogleSerperAPIWrapper(type=\"images\")\n",
|
||
"results = search.results(\"Lion\")\n",
|
||
"pprint.pp(results)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "85a3bed3",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Searching for Google News\n",
|
||
"We can also query Google News using this wrapper. For example:"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 8,
|
||
"id": "afc48b39",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:34.984087Z",
|
||
"start_time": "2023-05-04T00:54:33.369231Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'searchParameters': {'q': 'Tesla Inc.',\n",
|
||
" 'gl': 'us',\n",
|
||
" 'hl': 'en',\n",
|
||
" 'type': 'news',\n",
|
||
" 'num': 10,\n",
|
||
" 'engine': 'google'},\n",
|
||
" 'news': [{'title': 'Tesla stock soars after DoT unveils new self-driving car '\n",
|
||
" 'rules, set for near-20% weekly rally',\n",
|
||
" 'link': 'https://finance.yahoo.com/news/tesla-stock-soars-after-dot-unveils-new-self-driving-car-rules-set-for-near-20-weekly-rally-183748972.html',\n",
|
||
" 'snippet': 'Tesla (TSLA) stock surged as much as 10% on Friday, '\n",
|
||
" 'putting shares on track to log a weekly gain north of '\n",
|
||
" '17% with several positive...',\n",
|
||
" 'date': '2 days ago',\n",
|
||
" 'source': 'Yahoo Finance',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTgHH9x2YIdRGyo1VpJC8b5sYrW5-UprLRAT3r4LQDYx1lX1DeNlunoU4mc2w&s',\n",
|
||
" 'position': 1},\n",
|
||
" {'title': 'Tesla Refunds Early India Bookings Signaling Entry Is '\n",
|
||
" 'Near',\n",
|
||
" 'link': 'https://www.bloomberg.com/news/articles/2025-04-25/tesla-tsla-refunds-early-india-bookings-signaling-entry-is-near',\n",
|
||
" 'snippet': \"Tesla Inc.'s India office is refunding early bookers of \"\n",
|
||
" 'its Model 3, according to emails seen by Bloomberg '\n",
|
||
" 'News, sparking speculation the...',\n",
|
||
" 'date': '1 day ago',\n",
|
||
" 'source': 'Bloomberg.com',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTme3lE48FWOyFuWDM-o3wZISjba30aHdoRluMkt7zqlrYqCKK5qGZnwbJ89g&s',\n",
|
||
" 'position': 2},\n",
|
||
" {'title': 'Musk needs to become a more normal CEO',\n",
|
||
" 'link': 'https://www.ft.com/content/4d10da88-5a0b-49b5-9b29-77286f1985ec',\n",
|
||
" 'snippet': 'And Tesla should become a more normal company.',\n",
|
||
" 'date': '10 hours ago',\n",
|
||
" 'source': 'Financial Times',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSbfTHj0V4haC2VU_bI6W_ZNegrScrmvbUrnkjvskZBzvpPh7WzBIjir342Gw&s',\n",
|
||
" 'position': 3},\n",
|
||
" {'title': \"Tesla: The 'Musk Put' Is In Play (NASDAQ:TSLA)\",\n",
|
||
" 'link': 'https://seekingalpha.com/article/4778551-tesla-musk-put-in-play',\n",
|
||
" 'snippet': \"Tesla: The 'Musk Put' Is In Play. Apr. 27, 2025 6:02 AM \"\n",
|
||
" 'ETTesla, Inc. (TSLA) Stock, TSLA:CA StockBYDDF, NIO, '\n",
|
||
" 'XPEV, GOOG, TSLA, TSLA:CA13 Comments 1 Like.',\n",
|
||
" 'date': '10 hours ago',\n",
|
||
" 'source': 'Seeking Alpha',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSumMVfOINSI7Xip8Z-wLXwg4mpTuryAk4RMJDL-tWTW5DAdi1yR2WVIezaVQ&s',\n",
|
||
" 'position': 4},\n",
|
||
" {'title': 'Tesla: US Federal Autonomous Vehicle Regulatory Framework '\n",
|
||
" 'Aligns With Our Thesis',\n",
|
||
" 'link': 'https://www.morningstar.com/stocks/tesla-us-federal-autonomous-vehicle-regulatory-framework-aligns-with-our-thesis',\n",
|
||
" 'snippet': \"Editor's Note: This analysis was originally published \"\n",
|
||
" 'as a stock note by Morningstar Equity Research. '\n",
|
||
" 'Securities In This Article. Tesla Inc.',\n",
|
||
" 'date': '1 day ago',\n",
|
||
" 'source': 'Morningstar',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT_C3JjwfGXEpLowp-cmCMpxTvoMQ3nmOrhya0aLsnIEBrQSorBX3OSCb1svg&s',\n",
|
||
" 'position': 5},\n",
|
||
" {'title': \"Elon Musk's Wealth Skyrockets By Billions As Tesla Stock \"\n",
|
||
" 'Rallies After Billionaire CEO Steps Back From DOGE',\n",
|
||
" 'link': 'https://www.benzinga.com/markets/25/04/44974342/elon-musks-wealth-skyrockets-by-billions-as-tesla-stock-rallies-after-billionaire-ceo-steps-back-from-doge',\n",
|
||
" 'snippet': 'The net worth of Elon Musk witnessed a staggering '\n",
|
||
" 'increase of $7.5 billion on Wednesday as shares of '\n",
|
||
" 'Tesla Inc. (NASDAQ: TSLA) experienced a...',\n",
|
||
" 'date': '3 days ago',\n",
|
||
" 'source': 'Benzinga',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTok4iKaGss1or69QeOrnUo8ZEprpI5Etbq6kepYjLBPlIjOOhiX8yRYWeIiw&s',\n",
|
||
" 'position': 6},\n",
|
||
" {'title': 'Why Tesla Inc. (TSLA) Soared Last Week',\n",
|
||
" 'link': 'https://finance.yahoo.com/news/why-tesla-inc-tsla-soared-180528904.html',\n",
|
||
" 'snippet': 'We recently published a list of Why These 10 Firms '\n",
|
||
" 'Recorded Double-Digit Gains Last Week. In this article, '\n",
|
||
" 'we are going to take a look at...',\n",
|
||
" 'date': '1 day ago',\n",
|
||
" 'source': 'Yahoo Finance',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTkQBI72ZwZ8mNhFQ58DLH4wJMyfpsA67ONuTDvvOfAjop5kTrOVcymDGairw&s',\n",
|
||
" 'position': 7},\n",
|
||
" {'title': 'Tesla Hikes Canadian Prices and Pushes Its Pre-Tariff '\n",
|
||
" 'Inventory',\n",
|
||
" 'link': 'https://www.bloomberg.com/news/articles/2025-04-26/tesla-hikes-canadian-prices-and-pushes-its-pre-tariff-inventory',\n",
|
||
" 'snippet': 'Tesla Inc. is raising prices in Canada and encouraging '\n",
|
||
" 'buyers to snap up cars imported before counter-tariffs '\n",
|
||
" 'were imposed on US-made...',\n",
|
||
" 'date': '1 day ago',\n",
|
||
" 'source': 'Bloomberg.com',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3pUCdm4COUa4ckj6l-_oqzQUQyPZ_TwxylDHsKfQ5OHaTeC5C14xi3xTPjw&s',\n",
|
||
" 'position': 8},\n",
|
||
" {'title': 'Tesla, Inc. (TSLA) Faces Weak Q1 Auto Revenues but '\n",
|
||
" 'Stresses Long-Term AI and Robotics Vision',\n",
|
||
" 'link': 'https://finance.yahoo.com/news/tesla-inc-tsla-faces-weak-142059117.html',\n",
|
||
" 'snippet': 'We recently compiled a list of the 12 AI Stocks '\n",
|
||
" 'Analysts Are Talking About Right Now. In this article, '\n",
|
||
" 'we are going to take a look at where...',\n",
|
||
" 'date': '1 day ago',\n",
|
||
" 'source': 'Yahoo Finance',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQAF15LDx0VBN7Yhpe99fDywZVZOe2rC4QAQgOyIXyRMMEbUURh_ujyCqQHQg&s',\n",
|
||
" 'position': 9},\n",
|
||
" {'title': 'Analyst Says Tesla (TSLA) Valuation Still ‘Incredibly '\n",
|
||
" 'Rich’ as Chinese Companies ‘Eat’ Its Market Share',\n",
|
||
" 'link': 'https://finance.yahoo.com/news/analyst-says-tesla-tsla-valuation-183703204.html',\n",
|
||
" 'snippet': 'We recently published a list of Top 10 Stocks to Watch '\n",
|
||
" 'Ahead of May. In this article, we are going to take a '\n",
|
||
" 'look at where Tesla, Inc.',\n",
|
||
" 'date': '2 hours ago',\n",
|
||
" 'source': 'Yahoo Finance',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTd5uofRE66VcJeA46Ewvop5DmICfn3q1dYjk7QydsDVIp12Qtn4rTtzQJJ4g&s',\n",
|
||
" 'position': 10}],\n",
|
||
" 'credits': 1}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"search = GoogleSerperAPIWrapper(type=\"news\")\n",
|
||
"results = search.results(\"Tesla Inc.\")\n",
|
||
"pprint.pp(results)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d42ee7b5",
|
||
"metadata": {},
|
||
"source": [
|
||
"If you want to only receive news articles published in the last hour, you can do the following:"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"id": "8e3824cb",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:54:41.786864Z",
|
||
"start_time": "2023-05-04T00:54:40.691905Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'searchParameters': {'q': 'Tesla Inc.',\n",
|
||
" 'gl': 'us',\n",
|
||
" 'hl': 'en',\n",
|
||
" 'type': 'news',\n",
|
||
" 'num': 10,\n",
|
||
" 'tbs': 'qdr:h',\n",
|
||
" 'engine': 'google'},\n",
|
||
" 'news': [{'title': 'Big Tech faces high-stakes earnings week amid tariff '\n",
|
||
" 'jitters',\n",
|
||
" 'link': 'https://seekingalpha.com/news/4436090-big-tech-faces-high-stakes-earnings-week-amid-tariff-jitters',\n",
|
||
" 'snippet': 'When Big Tech last reported earnings, President Donald '\n",
|
||
" 'Trump had just taken office, optimism over a pro-growth '\n",
|
||
" 'agenda was fueling a stock rally and...',\n",
|
||
" 'date': '3 minutes ago',\n",
|
||
" 'source': 'Seeking Alpha',\n",
|
||
" 'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ9sc9IB67rgImvp7XEOuMDzLhJ6uj7-kNRp6vCShZ7Z9KzDqAR2OeKyHeKvg&s',\n",
|
||
" 'position': 1}],\n",
|
||
" 'credits': 1}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"search = GoogleSerperAPIWrapper(type=\"news\", tbs=\"qdr:h\")\n",
|
||
"results = search.results(\"Tesla Inc.\")\n",
|
||
"pprint.pp(results)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3f13e9f9",
|
||
"metadata": {},
|
||
"source": [
|
||
"Some examples of the `tbs` parameter:\n",
|
||
"\n",
|
||
"`qdr:h` (past hour)\n",
|
||
"`qdr:d` (past day)\n",
|
||
"`qdr:w` (past week)\n",
|
||
"`qdr:m` (past month)\n",
|
||
"`qdr:y` (past year)\n",
|
||
"\n",
|
||
"You can specify intermediate time periods by adding a number:\n",
|
||
"`qdr:h12` (past 12 hours)\n",
|
||
"`qdr:d3` (past 3 days)\n",
|
||
"`qdr:w2` (past 2 weeks)\n",
|
||
"`qdr:m6` (past 6 months)\n",
|
||
"`qdr:m2` (past 2 years)\n",
|
||
"\n",
|
||
"For all supported filters simply go to [Google Search](https://google.com), search for something, click on \"Tools\", add your date filter and check the URL for \"tbs=\".\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "38d4402c",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Searching for Google Places\n",
|
||
"We can also query Google Places using this wrapper. For example:"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 10,
|
||
"id": "e7881203",
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2023-05-04T00:56:07.271164Z",
|
||
"start_time": "2023-05-04T00:56:05.645847Z"
|
||
},
|
||
"collapsed": false,
|
||
"jupyter": {
|
||
"outputs_hidden": false
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'searchParameters': {'q': 'Italian restaurants in Upper East Side',\n",
|
||
" 'gl': 'us',\n",
|
||
" 'hl': 'en',\n",
|
||
" 'type': 'places',\n",
|
||
" 'num': 10,\n",
|
||
" 'engine': 'google'},\n",
|
||
" 'places': [{'position': 1,\n",
|
||
" 'title': \"Tony's Di Napoli\",\n",
|
||
" 'address': '1081 3rd Ave, New York, NY 10065',\n",
|
||
" 'latitude': 40.7643567,\n",
|
||
" 'longitude': -73.9642373,\n",
|
||
" 'rating': 4.6,\n",
|
||
" 'ratingCount': 2900,\n",
|
||
" 'priceLevel': '$$',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(212) 888-6333',\n",
|
||
" 'website': 'http://www.tonysnyc.com/',\n",
|
||
" 'cid': '1820798058748048984'},\n",
|
||
" {'position': 2,\n",
|
||
" 'title': \"L'Osteria\",\n",
|
||
" 'address': '1219 Lexington Ave, New York, NY 10028',\n",
|
||
" 'latitude': 40.7771565,\n",
|
||
" 'longitude': -73.9571345,\n",
|
||
" 'rating': 4.7,\n",
|
||
" 'ratingCount': 268,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(646) 524-6294',\n",
|
||
" 'website': 'http://www.losterianyc.com/',\n",
|
||
" 'cid': '13046004590297227899'},\n",
|
||
" {'position': 3,\n",
|
||
" 'title': 'La Pecora Bianca UES',\n",
|
||
" 'address': '1562 2nd Ave, New York, NY 10028',\n",
|
||
" 'latitude': 40.7746814,\n",
|
||
" 'longitude': -73.9538665,\n",
|
||
" 'rating': 4.8,\n",
|
||
" 'ratingCount': 1300,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(212) 300-9840',\n",
|
||
" 'website': 'https://www.lapecorabianca.com/',\n",
|
||
" 'cid': '6580713665095712525'},\n",
|
||
" {'position': 4,\n",
|
||
" 'title': 'Masseria East',\n",
|
||
" 'address': '1404 3rd Ave, New York, NY 10075',\n",
|
||
" 'latitude': 40.774910000000006,\n",
|
||
" 'longitude': -73.957163,\n",
|
||
" 'rating': 4.7,\n",
|
||
" 'ratingCount': 299,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(212) 535-3520',\n",
|
||
" 'website': 'http://www.masseriaeast.com/',\n",
|
||
" 'cid': '1165555394655432498'},\n",
|
||
" {'position': 5,\n",
|
||
" 'title': 'Pavin 86',\n",
|
||
" 'address': '1663 1st Ave, New York, NY 10028',\n",
|
||
" 'latitude': 40.777448,\n",
|
||
" 'longitude': -73.94927679999999,\n",
|
||
" 'rating': 5,\n",
|
||
" 'ratingCount': 11,\n",
|
||
" 'priceLevel': '$20–30',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(646) 368-1666',\n",
|
||
" 'cid': '14616385514965614026'},\n",
|
||
" {'position': 6,\n",
|
||
" 'title': 'Piccola Cucina Uptown',\n",
|
||
" 'address': '106 E 60th St, New York, NY 10022',\n",
|
||
" 'latitude': 40.7632756,\n",
|
||
" 'longitude': -73.96896149999999,\n",
|
||
" 'rating': 4.6,\n",
|
||
" 'ratingCount': 1900,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(646) 707-3997',\n",
|
||
" 'website': 'https://www.piccolacucinagroup.com/',\n",
|
||
" 'cid': '12569403914342629464'},\n",
|
||
" {'position': 7,\n",
|
||
" 'title': 'La Voglia NYC',\n",
|
||
" 'address': '1645 3rd Ave, New York, NY 10128',\n",
|
||
" 'latitude': 40.782702,\n",
|
||
" 'longitude': -73.95094569999999,\n",
|
||
" 'rating': 4.4,\n",
|
||
" 'ratingCount': 360,\n",
|
||
" 'priceLevel': '$50–100',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(212) 417-0181',\n",
|
||
" 'website': 'http://www.lavoglianyc.com/',\n",
|
||
" 'cid': '1355377864710486791'},\n",
|
||
" {'position': 8,\n",
|
||
" 'title': 'da Adriano',\n",
|
||
" 'address': '1198 1st Ave, New York, NY 10065',\n",
|
||
" 'latitude': 40.7631383,\n",
|
||
" 'longitude': -73.95919169999999,\n",
|
||
" 'rating': 4.8,\n",
|
||
" 'ratingCount': 240,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(646) 371-9412',\n",
|
||
" 'website': 'http://daadriano.com/',\n",
|
||
" 'cid': '988704178780025788'},\n",
|
||
" {'position': 9,\n",
|
||
" 'title': 'L’incontro by Rocco',\n",
|
||
" 'address': '1572 2nd Ave, New York, NY 10028',\n",
|
||
" 'latitude': 40.7749695,\n",
|
||
" 'longitude': -73.95354739999999,\n",
|
||
" 'rating': 4.7,\n",
|
||
" 'ratingCount': 1400,\n",
|
||
" 'priceLevel': '$50–100',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(718) 721-3532',\n",
|
||
" 'website': 'https://www.lincontrobyrocco.com/',\n",
|
||
" 'cid': '7698736469939478155'},\n",
|
||
" {'position': 10,\n",
|
||
" 'title': 'Water & Wheat',\n",
|
||
" 'address': '1379 3rd Ave, New York, NY 10075',\n",
|
||
" 'latitude': 40.7738747,\n",
|
||
" 'longitude': -73.9573571,\n",
|
||
" 'rating': 4.7,\n",
|
||
" 'ratingCount': 245,\n",
|
||
" 'priceLevel': '$30–50',\n",
|
||
" 'category': 'Italian restaurant',\n",
|
||
" 'phoneNumber': '(646) 484-5054',\n",
|
||
" 'website': 'http://www.waterandwheatnyc.com/',\n",
|
||
" 'cid': '14865033522272348854'}],\n",
|
||
" 'credits': 1}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"search = GoogleSerperAPIWrapper(type=\"places\")\n",
|
||
"results = search.results(\"Italian restaurants in Upper East Side\")\n",
|
||
"pprint.pp(results)"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "venv",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.12.7"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|