SerpAPI - Search API

在这里插入图片描述


文章目录

    • 关于 SerpAPI
      • serpapi & google-search-results
      • http 请求示例:
    • Python 调用示例
    • Basic Examples in Python
      • Search Bing
      • Search Baidu
      • Search Yahoo
      • Search YouTube
      • Search Walmart
      • Search eBay
      • Search Naver
      • Search Home Depot
      • Search Apple App Store
      • Search DuckDuckGo
      • Search Google
      • Search Google Scholar
      • Search Google Autocomplete
      • Search Google Product
      • Search Google Reverse Image
      • Search Google Events
      • Search Google Local Services
      • Search Google Maps
      • Search Google Jobs
      • Search Google Play
      • Search Google Images


关于 SerpAPI

  • 官网:https://serpapi.com
  • 官方文档:https://serpapi-python.readthedocs.io/en/latest/
  • PYPI : https://pypi.org/project/serpapi/
  • github : https://github.com/serpapi
    • Google Search Results in Python
      https://github.com/serpapi/google-search-results-python
    • serpapi-python
      https://github.com/serpapi/serpapi-python
  • LangChain - Serpapi https://www.langchain.com.cn/ecosystem/serpapi

This repository is the home of the soon–to–be official Python API wrapper for SerpApi. This serpapimodule allows you to access search data in your Python application.

SerpApi supports Google, Google Maps, Google Shopping, Bing, Baidu, Yandex, Yahoo, eBay, App Stores, and more. Check out the documentation for a full list.


serpapi & google-search-results

Please note that this package is separate from the legacy serpapi module, which is available on PyPi as google-search-results.

This package is maintained by SerpApi, and is the recommended way to access the SerpApi service from Python.


有四种方案,其中免费的如下

我的CN手机号,没有收到验证码,所以注册失败

在这里插入图片描述



http 请求示例:

https://serpapi.com/search.json?q=Coffee&location=Austin,+Texas,+United+States&hl=en&gl=us&google_domain=google.com
https://serpapi.com/search.json?q=Coffee&location=Brazil&hl=pt&gl=br&google_domain=google.com.br


Python 调用示例

pip install serpapi

from serpapi import GoogleSearchparams = {"q": "Coffee","location": "Austin, Texas, United States","hl": "en","gl": "us","google_domain": "google.com","api_key": "secret_api_key"
}search = GoogleSearch(params)
results = search.get_dict()

Let’s start by searching for Coffee on Google:

>>> import serpapi
>>> s = serpapi.search(q="Coffee", engine="google", location="Austin, Texas", hl="en", gl="us")
# s 是一个 SerpResults 对象,像是一个标准 dict,上面添加了一些便捷的功能# 打印日志:
>>> s["organic_results"][0]["link"]
'https://en.wikipedia.org/wiki/Coffee'# 打印第一个结果,以 Python 的方式
>>> s["organic_results"][0].get("title")
'Coffee - Wikipedia'

s 内容如下:

{"search_metadata": {"id": "6602701cfe41d084fd3ed5da","status": "Success","json_endpoint": "https://serpapi.com/searches/a15e1b92727f292c/6602701cfe41d084fd3ed5da.json","created_at": "2024-03-26 06:50:04 UTC","processed_at": "2024-03-26 06:50:04 UTC","google_url": "https://www.google.com/search?q=Coffee&oq=Coffee&uule=w+CAIQICIdQXVzdGluLFRYLFRleGFzLFVuaXRlZCBTdGF0ZXM&hl=en&gl=us&sourceid=chrome&ie=UTF-8","raw_html_file": "https://serpapi.com/searches/a15e1b92727f292c/6602701cfe41d084fd3ed5da.html","total_time_taken": 7.62},"search_parameters": {"engine": "google","q": "Coffee","location_requested": "Austin, Texas","location_used": "Austin,TX,Texas,United States","google_domain": "google.com","hl": "en","gl": "us","device": "desktop"},"search_information": {"query_displayed": "Coffee","total_results": 5760000000,"time_taken_displayed": 0.37,"organic_results_state": "Results for exact spelling"},"local_map": {"link": "https://www.google.com/search?sca_esv=6cb148437a7a9a38&gl=us&hl=en&q=Coffee&npsic=0&rflfq=1&rldoc=1&rllag=31994604,-99807361,55029&tbm=lcl&sa=X&ved=2ahUKEwizk5Ccq5GFAxUDjokEHeceA94QtgN6BAglEAE","image": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/2677b372a72544dbbc26036d5c7b09db.png","gps_coordinates": {"latitude": 31.994604,"longitude": -99.807361,"altitude": 55029}},"local_results": {"places": [{"position": 1,"rating": 4.7,"reviews_original": "(63)","reviews": 63,"description": "Dine-in\u00b7Drive-through\u00b7No delivery","place_id": "16666839338430965111","place_id_search": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&ludocid=16666839338430965111&q=Coffee","lsig": "AB86z5WD7smQJJZYj7Eh1KXWdsl2","thumbnail": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/47f37fc32e9075402698b02afcfe658f15416b9c44ead714051999e4f099a16f03170b796c045734.jpeg","service_options": {"dine_in": true,"drive_through": true,"no_delivery": true},"title": "The Branch Coffeehouse","type": "Coffee shop","address": "Tuscola, TX","hours": "Closed \u22c5 Opens 6 AM"},{"position": 2,"rating": 4.3,...},{"position": 3,"rating": 4.8,...}],"more_locations_link": "https://www.google.com/search?sca_esv=6cb148437a7a9a38&gl=us&hl=en&tbs=lf:1,lf_ui:9&tbm=lcl&q=Coffee&rflfq=1&num=10&uule=w+CAIQICIdQXVzdGluLFRYLFRleGFzLFVuaXRlZCBTdGF0ZXM&sa=X&ved=2ahUKEwizk5Ccq5GFAxUDjokEHeceA94QjGp6BAgrEAE"},"immersive_products": [{"thumbnail": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/49e6224fb883d7093d9d5db8b6707fcdcb9bf962cec4743d996f7845da535981.webp","source": "Amazon.com, 10+","title": "Folgers Classic Roast Ground Coffee","price": "$4.49","extracted_price": 4.49,"immersive_product_page_token": "eyJlaSI6IkluQU...lZSJ9","serpapi_link": "https://serpapi.com/search.json?engine=google_immersive_product&page_token=eyJlaS...UENfZmZlZSJ9"},{"thumbnail": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/49e6224fb883d7093d9d5db8b6707fcd77fcca065cb1ab76d1fc85c40626c4b4.webp","source": "Black Rifle Coffee Company, 10+","title": "Black Rifle Coffee Company Murdered Out Coffee Roast","price": "$16.99","extracted_price": 16.99,"immersive_product_page_token": "eyJlaSI6IkluQUNaclA2QklPY3B0UV....UFJPRF9QQ18xNTQ3NzA1NTU4Nzk2OTQ3MTc4NSIsInF1ZXJ5IjoiQ29mZmVlIn0=","serpapi_link": "https://serpapi.com/search.json?engine=google_immer...oiQ29mZmVlIn0%3D"},{..."title": "Bones Coffee Company New Flavors! Favorite Flavors Sample Pack 4 oz Pack of 5 Assorted Coffee Beans",...},...{..."title": "Starbucks Breakfast Blend Medium Roast Ground Coffee",...}],"related_questions": [{"question": "Is coffee actually healthy for you?","snippet": "Hu said that moderate coffee intake\u2014about 2\u20135 cups a day\u2014is linked to a lower likelihood of type 2 diabetes, heart disease, liver and endometrial cancers, Parkinson's disease, and depression. It's even possible that people who drink coffee can reduce their risk of early death.","title": "Is coffee good or bad for your health? | News - hsph.harvard.edu","link": "https://www.hsph.harvard.edu/news/hsph-in-the-news/is-coffee-good-or-bad-for-your-health/#:~:text=Hu%20said%20that%20moderate%20coffee,their%20risk%20of%20early%20death.","displayed_link": "https://www.hsph.harvard.edu \u203a news \u203a hsph-in-the-news","source_logo": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/b460e89a15194171da0396937f5d7133523eb116b317ef2548aa4c977ab879e3.png","next_page_token": "eyJvbnMiOiIx...XzIifQ==","serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=..."},...{"question": "What are the 4 types of coffee?","snippet": "Learn about the four most popular types of coffee beans\u2014Arabica, Robusta, Excelsa and Liberica\u2014and when to use them.","title": "4 Types of Coffee Beans: How to Choose - KitchenAid",...}],"organic_results": [{"position": 1,"title": "Coffee","link": "https://en.wikipedia.org/wiki/Coffee","redirect_link": "https://www.google.comhttps://en.wikipedia.org/wiki/Coffee","displayed_link": "https://en.wikipedia.org \u203a wiki \u203a Coffee","thumbnail": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/19875953fd2763176ecb268a71b09fd91b6fe1da2d76a8e70422cfe845dba055.jpeg","favicon": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/19875953fd2763176ecb268a71b09fd980eab7533207994f46f9cbdee41bc698.png","snippet": "Coffee is a beverage brewed from roasted coffee beans. Darkly colored, bitter, and slightly acidic, coffee has a stimulating effect on humans, primarily due ...","snippet_highlighted_words": ["Coffee","coffee","coffee"],"sitelinks": {"inline": [{"title": "History","link": "https://en.wikipedia.org/wiki/History_of_coffee"},{"title": "Coffee bean","link": "https://en.wikipedia.org/wiki/Coffee_bean"},{"title": "Coffee production","link": "https://en.wikipedia.org/wiki/Coffee_production"},{"title": "Coffee preparation","link": "https://en.wikipedia.org/wiki/Coffee_preparation"}]},"source": "Wikipedia"},...{"position": 6,"title": "Counter Culture Coffee",..."snippet_highlighted_words": ["Coffee","coffee","coffee","coffee"],"sitelinks": {"inline": [{"title": "Our Coffees","link": "https://counterculturecoffee.com/collections/coffee"},...{"title": "Subscriptions","link": "https://counterculturecoffee.com/pages/on-going-subscription"}]},"rich_snippet": {"top": {"detected_extensions": {"free_day_delivery": 1},"extensions": ["Free 1\u20134 day delivery"]}},"source": "Counter Culture Coffee"},{"position": 7,"title": "Coffee | The Nutrition Source - hsph.harvard.edu",...},{"position": 8,"title": "Blanchard's Coffee Roasting Company",..."sitelinks": {"inline": [{"title": "Products","link": "https://blanchardscoffee.com/collections/all"},{"title": "Decent Instant Coffee","link": "https://blanchardscoffee.com/products/decent"},{"title": "Blanchard's Cafe Pickup","link": "https://pickup.blanchardscoffee.com/"},{"title": "Shop","link": "https://blanchardscoffee.com/pages/shop"}]},"rich_snippet": {"top": {"detected_extensions": {"price": 14,"currency": "$ to $","unknown": 5},"extensions": ["$14 to $15","\u200e 5","day delivery"]}},"source": "Blanchard's Coffee"},{"position": 9,"title": "The Coffee Bean & Tea Leaf | CBTL","link": "https://www.coffeebean.com/","redirect_link": "https://www.google.comhttps://www.coffeebean.com/","displayed_link": "https://www.coffeebean.com","favicon": "https://serpapi.com/searches/6602701cfe41d084fd3ed5da/images/19875953fd2763176ecb268a71b09fd9f88be5e04c633b3b580c37b1b81751ac.png","snippet": "Born and brewed in Southern California since 1963, The Coffee Bean & Tea Leaf\u00ae is passionate about connecting loyal customers with carefully handcrafted ...","snippet_highlighted_words": ["Coffee"],"source": "The Coffee Bean & Tea Leaf"}],"related_searches": [{"block_position": 1,"query": "Coffee shops near Texas","image": "https://lh5.googleusercontent.com/p/AF1QipOYChzmH_DA-1Yz3mF8lQyEcinfGtJzaiUBxyUP=w40-h40-n-k-no"},{"block_position": 2,"query": "Great coffee shop near Texas","image": "https://lh5.googleusercontent.com/p/AF1QipOYChzmH_DA-1Yz3mF8lQyEcinfGtJzaiUBxyUP=w40-h40-n-k-no"},...{"block_position": 1,"query": "coffee powder",...}],"refine_this_search": [{"query": "Whole Bean","link": "https://www.google.com/search?sca_esv=6cb148437a7a9a38&gl=us&hl=en&q=whole+bean+coffee&sa=X&ved=2ahUKEwizk5Ccq5GFAxUDjokEHeceA94Qs9oBKAB6BAguEAE","serpapi_link": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&q=whole+bean+coffee","thumbnail": "https://encrypted-tbn2.gstatic.com/shopping?q=tbn:ANd9GcTJVcQZ1jGbu7SLjXBxneWc_xYUvdxhPAI1Gflp9AMbK4w7HS5fw3ItzDKnAx5qEle9SIbzx4FE9CZVnBoJDcN1jdTfbWEM50gozzPkGxbTQJ8236a419jb"},...{"query": "Bag",...},{"query": "Box",...}],"pagination": {"current": 1,"next": "https://www.google.com/search?q=Coffee&oq=Coffee&hl=en&gl=us&start=10&sourceid=chrome&ie=UTF-8","other_pages": {"2": "https://www.google.com/search?q=Coffee&oq=Coffee&hl=en&gl=us&start=10&sourceid=chrome&ie=UTF-8",..."5": "https://www.google.com/search?q=Coffee&oq=Coffee&hl=en&gl=us&start=40&sourceid=chrome&ie=UTF-8"}},"serpapi_pagination": {"current": 1,"next_link": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&q=Coffee&start=10","next": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&q=Coffee&start=10","other_pages": {"2": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&q=Coffee&start=10",..."5": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas&q=Coffee&start=40"}}
}

The SerpApi.com API Documentation contains a list of all the possible parameters that can be passed to the API.


Basic Examples in Python

Search Bing

import os
import serpapiclient = serpapi.Client(api_key=os.getenv("API_KEY"))results = client.search({'engine': 'bing','q': 'coffee',
})
  • API Documentation: serpapi.com/bing-search-api

Search Baidu

results = client.search({'engine': 'baidu','q': 'coffee',
})
  • API Documentation: serpapi.com/baidu-search-api

Search Yahoo

results = client.search({'engine': 'yahoo','p': 'coffee',
})
  • API Documentation: serpapi.com/yahoo-search-api

Search YouTube

results = client.search({'engine': 'youtube','search_query': 'coffee',
})
  • API Documentation: serpapi.com/youtube-search-api

Search Walmart

results = client.search({'engine': 'walmart','query': 'coffee',
})
  • API Documentation: serpapi.com/walmart-search-api

Search eBay

results = client.search({'engine': 'ebay','_nkw': 'coffee',
})
  • API Documentation: serpapi.com/ebay-search-api

Search Naver

results = client.search({'engine': 'naver','query': 'coffee',
})
  • API Documentation: serpapi.com/naver-search-api

Search Home Depot

results = client.search({'engine': 'home_depot','q': 'table',
})
  • API Documentation: serpapi.com/home-depot-search-api

Search Apple App Store

results = client.search({'engine': 'apple_app_store','term': 'coffee',
})
  • API Documentation: serpapi.com/apple-app-store

Search DuckDuckGo

results = client.search({'engine': 'duckduckgo','q': 'coffee',
})
  • API Documentation: serpapi.com/duckduckgo-search-api

Search Google

results = client.search({'engine': 'google','q': 'coffee','engine': 'google',
})
  • API Documentation: serpapi.com/search-api

Search Google Scholar

results = client.search({'engine': 'google_scholar','q': 'coffee',
})
  • API Documentation: serpapi.com/google-scholar-api

Search Google Autocomplete

results = client.search({'engine': 'google_autocomplete','q': 'coffee',
})
  • API Documentation: serpapi.com/google-autocomplete-api

Search Google Product

results = client.search({'engine': 'google_product','q': 'coffee','product_id': '4887235756540435899',
})
  • API Documentation: serpapi.com/google-product-api

Search Google Reverse Image

results = client.search({'engine': 'google_reverse_image','image_url': 'https://i.imgur.com/5bGzZi7.jpg','max_results': '1',
})
  • API Documentation: serpapi.com/google-reverse-image

Search Google Events

results = client.search({'engine': 'google_events','q': 'coffee',
})
  • API Documentation: serpapi.com/google-events-api

Search Google Local Services

results = client.search({'engine': 'google_local_services','q': 'electrician','data_cid': '6745062158417646970',
})
  • API Documentation: serpapi.com/google-local-services-api

Search Google Maps

results = client.search({'engine': 'google_maps','q': 'pizza','ll': '@40.7455096,-74.0083012,15.1z','type': 'search',
})
  • API Documentation: serpapi.com/google-maps-api

Search Google Jobs

results = client.search({'engine': 'google_jobs','q': 'coffee',
})
  • API Documentation: serpapi.com/google-jobs-api

Search Google Play

results = client.search({'engine': 'google_play','q': 'kite','store': 'apps','max_results': '2',
})
  • API Documentation: serpapi.com/google-play-api

Search Google Images

results = client.search({'engine': 'google_images','tbm': 'isch','q': 'coffee',
})
  • API Documentation: serpapi.com/images-results

2024-03-26(二)
头晕

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/568873.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【中文视觉语言模型+本地部署 】23.08 阿里Qwen-VL:能对图片理解、定位物体、读取文字的视觉语言模型 (推理最低12G显存+)

项目主页:https://github.com/QwenLM/Qwen-VL 通义前问网页在线使用——(文本问答,图片理解,文档解析):https://tongyi.aliyun.com/qianwen/ 论文v3. : 一个全能的视觉语言模型 23.10 Qwen-VL: A Versatile…

[Java基础揉碎]抽象类

目录 通过问题引出 介绍 关键点 细节 ​编辑 抽象类的最佳设计模式--模版设计模式 1.先用最容易想到的方法 2.分析问题,提出使用模板设计模式 通过问题引出 假如我们有个动物类, 动物都有eat吃的方法, 但是具体吃什么, 我们不知道, 因为是什么动物我们不知道…

创建AI智能体

前言 灵境矩阵是百度推出的基于文心大模型的智能体(Agent)平台,支持广大开发者根据自身行业领域、应用场景,选取不同类型的开发方式,打造大模型时代的产品能力。开发者可以通过 prompt 编排的方式低成本开发智能体&am…

成都爱尔胡建斌院长强调黄斑病变是眼睛哪儿出了问题

黄斑位于眼球内部的眼底的视网膜区域,处于人眼的光学中心区,是视力轴线的投影点。它是人眼视网膜中央视觉细胞最集中的部位。黄斑中心多为锥形细胞,对明暗不敏感,对色敏感。黄斑外围多为柱形细胞,对明暗敏感,对色几乎不…

时序数据预处理

时序数据预处理 对于数据科学来说,凡事“预”则立,不“预”则废。数据的质量直接决定数据挖掘的结果。本文旨在一站式的梳理时序数据的预处理步骤。 数据预处理的目的是将脏数据变成我们想要的干净的数据,这里的干净指的是: 准确…

基于Springboot+vue的图书馆管理系统+数据库+论文+免费远程调试

项目介绍: Springbootvue的图书馆管理系统。Javaee项目,springboot vue前后端分离项目 本文设计了一个基于Springbootvue的前后端分离的图书馆管理系统,采用M(model)V(view)C(controller&#x…

职场口才提升之道

职场口才提升之道 在职场中,口才的重要性不言而喻。无论是与同事沟通协作,还是向上级汇报工作,亦或是与客户洽谈业务,都需要具备良好的口才能力。一个出色的职场人,除了拥有扎实的专业技能外,还应具备出色…

U盘0字节的危机与救赎:原因分析与恢复攻略

一、遭遇U盘0字节的尴尬时刻 U盘,作为现代生活中不可或缺的数据存储工具,以其便携性和大容量深受用户喜爱。然而,当U盘突然显示为0字节,所有的文件和数据仿佛一夜之间消失无踪时,那种焦虑和绝望的感觉,恐怕…

用友BI方案:一键搞定财务、销售、生产等分析

别人家做用友的数据分析,从零开始搭建分析模型、设计BI数据可视化报表,反复测试修改,耗时耗力,效果未知。奥威BI做用友的数据分析,用用友BI方案,注册、下载执行,自动取数、计算指标、分析数据、…

【学习】软件测试中,我们如何有效地跟踪和管理缺陷?

在软件测试中,如何有效地跟踪和管理缺陷?别急,一起来看下小编今日带来的分享。 1.缺陷报告 建立一个缺陷报告系统,让用户和团队成员能够提交缺陷报告。确保缺陷报告中包括清晰的问题描述、重现步骤、预期结果和实际结果等信息。2…

java反射获取参数名

jdk中新增-parameters参数,开启此参数可以将编译后的class文件保留原码中的参数名 idea中可以安装jclasslib Bytecode Viewer查看编译结果 idea中的配置: 查看一个class: 可以看到一个 MethodParameters,如果没有-parameters参…

C语言学习--字符串和整型的转换

目录 整型→字符串 方法1:利用‘0’将单个数字转字符 方法2:利用sprintf函数 方法3:利用itoa函数 字符串→整型 方法1:利用-‘0’直接转换 方法2:利用atoi函数 整型→字符串 整形数据变成字符串,最…