有啥办法可以抓取/抓取谷歌搜索的“关于”部分?
Posted
技术标签:
【中文标题】有啥办法可以抓取/抓取谷歌搜索的“关于”部分?【英文标题】:Is there any way I can scrape/grab the "about" section of a google search?有什么办法可以抓取/抓取谷歌搜索的“关于”部分? 【发布时间】:2021-12-29 11:09:50 【问题描述】:我正在为学校构建一个 Flutter 应用程序,其中列出了犬种。我想知道是否可以为谷歌搜索查询下拉“关于部分”。我正在使用颤振/飞镖,但我认为这个问题与语言无关,我只想知道它是否可能。这就是我所说的:
我想抓取“关于”标题下的段落。这可能吗?
【问题讨论】:
【参考方案1】:你必须使用谷歌的这个 API https://developers.google.com/knowledge-graph
【讨论】:
谢谢,现在我只需要弄清楚如何在 dart 中访问这些嵌套的 JSON 元素... @Connor 欢迎您)使用 JSON,您可以从这里开始 - docs.flutter.dev/development/data-and-backend/json【参考方案2】:但是,您有很多方法可以做到这一点。您可以使用此 API 的一种方式称为 SerpApi
这将返回Json
中的结果
只需注册此服务。并且使用http
包,您可以获得这样的结果
import 'package:http/http.dart' as http;
var url = Uri.parse('https://serpapi.com/search');
var query = "Samoyed" // Your query;
var response = await http.get(url + "?q=$query&google_domain=google.com&api_key=secret_api_key");
print(response.body);
你会得到
"knowledge_graph":
"title":
"Samoyed",
"type":
"Dog breed",
"header_images":
[
"image":
"https://serpapi.com/searches/619669ffc47d3ccfb5511aa1/images/1dbd475a36109a83173d2d6a380adb0cd740843c4a06be6455a87b252b4811b3f717889baa84eb34.jpeg",
"source":
"https://en.wikipedia.org/wiki/Samoyed_dog"
,
"image":
"https://serpapi.com/searches/619669ffc47d3ccfb5511aa1/images/1dbd475a36109a83173d2d6a380adb0cd740843c4a06be6477e61734e5c35299fd9ba84a832499c2.jpeg",
"source":
"https://www.akc.org/dog-breeds/samoyed/"
,
"image":
"https://serpapi.com/searches/619669ffc47d3ccfb5511aa1/images/1dbd475a36109a83173d2d6a380adb0cd740843c4a06be641d71587a667af36fd5c22ede97ad0d5d.jpeg",
"source":
"https://www.thesprucepets.com/samoyed-dog-breed-profile-4586270"
,
"image":
"https://serpapi.com/searches/619669ffc47d3ccfb5511aa1/images/1dbd475a36109a83173d2d6a380adb0cd740843c4a06be6407d380d689b958ece6cfa86598a2b35e.jpeg",
"source":
"https://www.rover.com/blog/samoyed-puppies-complete-guide/"
,
"image":
"https://serpapi.com/searches/619669ffc47d3ccfb5511aa1/images/1dbd475a36109a83173d2d6a380adb0cd740843c4a06be64097c7c54fd3dce6ea08aeb17527d8bfa.jpeg",
"source":
"https://www.dailypaws.com/dogs-puppies/dog-breeds/samoyed"
,
"image":
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTDUBrb001EttjCvMAByRCKQvioc2KHy6rD7McCmeJ1wg&s",
"source":
"http://www.vetstreet.com/dogs/samoyed"
],
"description":
"The Samoyed is a breed of medium-sized herding dogs with thick, white, double-layer coats. They are a spitz-type dog which takes its name from the Samoyedic peoples of Siberia.",
"source":
"name":
"Wikipedia",
"link":
"https://en.wikipedia.org/wiki/Samoyed_dog"
,....
【讨论】:
以上是关于有啥办法可以抓取/抓取谷歌搜索的“关于”部分?的主要内容,如果未能解决你的问题,请参考以下文章