我有一个正在运行的 React 应用程序,我从外部 ASP.NET 应用程序获取页面。我只想获取页面的一部分而不是完整的页面。我不知道是否可以这样做。我的目标是只删除页面的主体。我的页面如下<!DOCTYPE html><html><head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Privacy Policy - DotnetApp</title> <link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="/css/site.css" /></head><body> <header> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <div class="container"> <a class="navbar-brand" href="/">DotnetApp</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse"> <ul class="navbar-nav flex-grow-1"> <li class="nav-item"> <a class="nav-link text-dark" href="/">Home</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="/Home/Privacy">Privacy</a> </li> </ul> </div> </div> </nav> </header> <div class="container"> <main role="main" class="pb-3"> <h1>Privacy Policy</h1><p>Use this page to detail your site's privacy policy.</p> </main> </div> <footer class="border-top footer text-muted"> <div class="container"> © 2020 - DotnetApp - <a href="/Home/Privacy">Privacy</a> </div> </footer></body></html>数据对象保存上面的 HTML 页面
1 回答
互换的青春
TA贡献1797条经验 获得超6个赞
您可以使用 DOMParser 接口将 html 解析为 DOM 树。例如:
let html = '<!DOCTYPE html><html><!-- some html --></html>' let doc = new DOMParser().parseFromString(html, 'text/html'); let bodyHtml = doc.body.innerHTML;
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报
0/150
提交
取消