【问题标题】:How to scrape <html>...</html> INSIDE another <html>...</html> with puppeteer如何使用 puppeteer 在另一个 <html>...</html> 中刮取 <html>...</html>
【发布时间】:2019-12-09 02:44:34
【问题描述】:

好的,所以我试图用 node.js puppeteer 抓取的页面是这样的结构

    <html lang = "en">
    ....
       <html xmlns="https://www.w3.org/1999/xhtml" lang="en">
            <a href = "link I'm trying to go to">Go to link</a>
       </html>
    </html>

我尝试通过选择器和 XPath 进行单击。两者都不起作用,我三次检查两者是否正确。感觉跟这个内嵌的html有点关系,不知道怎么处理?有人可以帮忙吗?

【问题讨论】:

  • 是在iframe里面吗?
  • 到目前为止你有什么尝试?
  • 正如@MarcosCasagrande 暗示的那样,如果您要抓取的内容在 iframe 内,则需要抓取 iframe 的 URL,因为 iframe 内容的 DOM 元素不可访问来自父文档。
  • @MarcosCasagrande 是的,它在 iframe 内。让我尝试抓取 iframe 的 url
  • @MichaelRodriguez 是的,它在 iframe 中。我将尝试抓取该网址

标签: javascript html node.js puppeteer


【解决方案1】:

其他 cmets 指出,无法从父文档访问 iframe 内的内容。我再次检查了代码,结果它实际上是这样的结构:

<html lang = "en">
....
   <iframe src = "url">
       <html xmlns="https://www.w3.org/1999/xhtml" lang="en">
           <a href = "link I'm trying to go to">Go to link</a>
       </html>
   </iframe>
</html>

所以我所要做的就是 page.goto(url),然后我就可以正常抓取了。谢谢大家!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2018-02-19
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多