如何使用JavaScript取得iframe的innerHTML
P粉358281574
P粉358281574 2024-02-26 20:10:02
0
1
361

我想從網頁中取得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-><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; bot : 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 tiapper-log;<div class="jsx-31,9858893 ti logo-container jsx-997609344"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/node/_next/static/images/logo-ktok-web/tiktok/web/node/_next/static/images/logo-ktok-web/tiktok/web/node/_next/static/images/logo- 7328701cc .svg" title="TikTok" class="jsx-1929089525 logo-icon"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/ktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/ktok-web. node/_next/static/images/logotext-9b4d14640f93065ec36dab71c806e135.svg" title="TikTok" class="jsx-1929089525 logo-texttext">
將部分 html 分解到此,以便您可以更好地看到更多內容。

`<iframe src="https:

我嘗試將 html 元素的 iframe 部分添加到上面的 javascript 程式碼中,但它似乎沒有做任何事情。 我確信我做錯了什麼,可能需要對程式碼進行更多調整。

P粉358281574
P粉358281574

全部回覆(1)
P粉659518294
(document.getElementById('YOUR ID').contentDocument).body;
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!