首页  >  问答  >  正文

如何使用JavaScript获取iframe的innerHTML

我想从网页中获取innerHTML。它在页面 html 文档的正文内容中使用 iframe。

这是我正在使用的代码,但似乎没有发生任何事情。我也知道它们一定是我这里的代码中的一些问题,这就是为什么它不能正常工作的原因。

document.querySelectorAll('"body > iframe"')[0].innerHTML; 到目前为止我已经尝试过这一点,并且我正在网上查找是否可以以某种方式使其工作。

这是从浏览器调试器工具中手动提取的代码的 html 部分。

<body><div id="__next"><div id="main" class="jsx-834240835 desktop-container"><div class="jsx-1905932170 header-container white"><div class="jsx-1905932170 header-content"><div class="jsx-1905932170 hamburger-wrapper"><a href="https://www.tiktok.com/en"><a title="TikTok" class="jsx-3359950850 logo-link">/div><iframe src="https://www.tiktok.com/creator#/upload?lang=en/" style="height: 650px; border-style: none; width: 100%; margin-bottom: -6px;"></iframe><div style="visibility: hidden; position: absolute; bottom: 0px; left: 0px; right: 0px; height: 356px; z-index: -1;"></div><div id="creator-center-footer"><div class="jsx-3176438893 footer-container"><footer class="jsx-3176438893 footer-content-wrapper"><div class="jsx-3176438893 tiktok-logo"><div class="jsx-1929089525 logo-container jsx-997609344"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/node/_next/static/images/logo-7328701c910ebbccb5670085d243fc12.svg" title="TikTok" class="jsx-1929089525 logo-icon"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/node/_next/static/images/logotext-9b4d14640f93065ec36dab71c806e135.svg" title="TikTok" class="jsx-1929089525 logo-text"></div><strong

将部分 html 分解到此,以便您可以更好地看到更多内容。

`<iframe src="https:

我尝试将 html 元素的 iframe 部分添加到上面的 javascript 代码中,但它似乎没有做任何事情。 我确信我做错了什么,可能需要对代码进行更多调整。

P粉358281574P粉358281574236 天前371

全部回复(1)我来回复

  • P粉659518294

    P粉6595182942024-02-27 00:30:05

    雷雷

    回复
    0
  • 取消回复