我应该使用 Yahoo-Pipes 来抓取 div 的内容吗?

发布于 2024-07-25 22:44:12 字数 753 浏览 5 评论 0原文

给定:

  • 网址 - http://www.contoso.com/search.php? q={param} 返回:

    -html-
    --正文-
    {...}
    ---div id='foo'-
    ----div id='第1页'/-
    ----div id='第2页'/-
    ----div id='page3'/-
    ----div id='第N页'/-
    ---/div-
    {...}
    --/body-
    -/html-

需要:

  • div id='foo' 的innerHtml 必须由客户端获取(即Javascript)。
    • 它将被分成离散的项目(即 div id='page1' 到 div id='pageN')。
  • API 限制会阻止服务器端代码预取数据,因此解析和操作的负担必须放在客户端上。

问题:

  • Yahoo-Pipes 能否帮助格式化数据以便于使用?
    • 缺少 DOM 解析器让我犹豫不决。
  • 是否有任何现有管道可以作为示例?

Given:

  • Url - http://www.contoso.com/search.php?q={param} returns:

    -html-
    --body-
    {...}
    ---div id='foo'-
    ----div id='page1'/-
    ----div id='page2'/-
    ----div id='page3'/-
    ----div id='pageN'/-
    ---/div-
    {...}
    --/body-
    -/html-

Wanted:

  • The innerHtml of div id='foo' must be fetched by the client (i.e. Javascript).
    • It will be split into discrete items (i.e. div id='page1' to div id='pageN').
  • API Throttling prevents server-side code from pre-fetching the data, so the parsing and manipulation burden must be placed on the client.

Question:

  • Could Yahoo-Pipes help format the data for easier consumption?
    • The lack of a DOM parser gives me pause.
  • Are there any existing pipes that could serve as an example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2024-08-01 22:44:12

您可以使用 YQL 模块,它允许您获取任意 URL,然后使用 XPath 解析它们。 YQL 查询示例:

select * from html where url="http://finance.yahoo.com/q?s=yhoo" and
  xpath='//div[@id="yfi_headlines"]/div[2]/ul/li/a'

You can use the YQL module, which allows you to fetch arbitrary URLs and then parse them with XPath. A sample YQL query:

select * from html where url="http://finance.yahoo.com/q?s=yhoo" and
  xpath='//div[@id="yfi_headlines"]/div[2]/ul/li/a'
甜味超标? 2024-08-01 22:44:12

是的,用 Y 就可以实现! 管道。 您只需要“操作符部分”中的两个模块:

第一个“子元素”即可仅获取内容。

然后只需使用“Regex”模块提取 div 内容并通过 JSON 从您的站点获取它:

搜索:

^.*?

(.*?)

;.*?$

替换:

$1

Yes, it's doable with Y! Pipes. You only need two modules from the 'Operators section':

First "Sub Element" to get only the content.

Then just use the "Regex" module to extract the div content and get it through JSON from your site:

Search:

^.*?<div id="foo">(.*?)</div>.*?$

Replace:

$1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文