V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gongcheng121
V2EX  ›  问与答

Node phantomjs 如何获取页面中 iframe 中的 html

  •  
  •   gongcheng121 · 2018-02-25 12:44:00 +08:00 · 2373 次点击
    这是一个创建于 2245 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 Nodejs 进行抓取页面的时候,js 等都可以运行,但是页面中包含一个 iframe,输出抓取的 html 的时候,iframe 中是空的,没有 dom。用的包是 Node-phantomjs。

    4 条回复    2018-02-26 10:01:26 +08:00
    xycool
        1
    xycool  
       2018-02-25 14:15:46 +08:00
    phantomjs --web-security=no 试试
    lemuria
        2
    lemuria  
       2018-02-25 18:20:28 +08:00
    document.querySelector('selector').contentWindow.document.documentElement.outerHTML
    lemuria
        3
    lemuria  
       2018-02-25 18:21:39 +08:00
    gongcheng121
        4
    gongcheng121  
    OP
       2018-02-26 10:01:26 +08:00
    @lemuria ok,我试试,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2892 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 02:45 · PVG 10:45 · LAX 19:45 · JFK 22:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.