|
Post by account_disabled on Jan 27, 2024 6:09:03 GMT -5
如今,我们使用的几乎所有服务都有某种 API。有些 Web 应用程序甚至仅从 API 点构建,并传递到某种前端视图。如果您是提供 API 的服务的使用者,您有时会需要更多功能或发现 API 可以提供的功能受到限制。在本文中,我们将介绍一项对 API 使用者和创建者都有用的服务。 Play Next Unmute Current Time 0:05 / Duration 2:00 Fullscreen Backward Skip 10s Play Video Forward Skip 10s 我总是同意这样的说法:如果有 Web 界面,您就可以在其上构建自己的 API。WrapAPI试图让这个过程变得更容易。如果您熟悉网页抓取/爬行(或从网站提取数据)的过程,您就会看到 WrapAPI 的魔力。 WrapAPI 提供的服务可让您轻松地从网站提取信息并根据数据创建 API。它提供了一种简单的交互式方式来选择您想要获取的信息。只需点击几下,您就可以在线使用您的 API。 要学习本教程,我建议您访问并创建一个帐户。 如何绕过 WrapAPI 在 WrapAPI 网站上,您将看到您可以立即开始构建项目 - 不过,除非您创建帐户,否则您的工作将不会被保存。我们仅介绍GET方法,因为我们只想在本例中获取数据。 URL 栏下方有四个按钮,可提供有关您正在查看的网站的不同信息。浏览器 WhatsApp 号码数据 视图显示该站点,就像您从浏览器访问该站点一样。代码视图显示站点的源代码。标头显示您从服务器获得的响应。如果您想查看从服务器获得的响应,这非常有用:它为您提供 HTTP 状态代码(200、404、400 等)、内容类型、Web 服务器等信息。您还可以直接从构建器查看请求的Cookie 。 获取数据 现在您应该能够在浏览器视图框架内看到 SitePoint。 WrapAPI Builder 中的 SitePoint 预览 让我们创建一个非常简单的 API,向我们显示 JavaScript 频道的最新帖子标题。如果将鼠标悬停在网站中的标题、图像或任何其他元素上,您会注意到覆盖它的选择颜色。 让我们向下滚动一点,到最新文章部分。将鼠标悬停在其中一篇文章的标题上,然后单击该标题。您会注意到它不会切换到我们单击的特定链接。我们看到本节中的每个标题都突出显示。WrapAPI猜测这些都是我们想要的标题。有时它也可以选择我们不想要的网站的一部分。当 CSS 类选择器未明确定义或未被站点中的其他元素使用时,通常会出现这种情况。 除了 CSS 选择器之外,WrapAPI 还支持正则表达式、JSON 选择器、标头、cookie、表单输出以及更多选项。您可以将它们一起使用并准确提取您的目标。在此示例中,我们将仅使用 CSS 选择器。 在构建器中选择标题 Learn to Code with JavaScript 在界面的右侧,您将看到三个选项卡。让我们看一下当前的“构建”选项卡。输出将向我们显示选择器(在我们的例子中是 CSS 选择器),您将获得有关您想要选择的内容的更多详细信息。我们只对提取标题(即文本)感兴趣。
|
|