gpt4 book ai didi

javascript - 操作 HTML 并放入数组

转载 作者:行者123 更新时间:2023-11-28 03:42:30 25 4
gpt4 key购买 nike

我有以下来自谷歌书签导出的 HTML。我想删除某些信息。文件夹层、URL、描述。

如果可能的话,我想使用 JavaScript(或其他任何东西)将输出信息放入一个数组中,然后我可以调用该数组。以 5 个变量结束。

$ root folder  - Test Folder 1 (Tier 1)
$ sub folder 1 - Test 1 (Tier 2)
$ sub folder 2 - Test 1 (Tier 3)
$ URL - https://stackoverflow.com/
$ Description - Stack Overflow

输入

<DL><p>
<DT><H3 ADD_DATE="1444728233" LAST_MODIFIED="1495547034" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
<DL><p>

<DT><H3 ADD_DATE="1495544136" LAST_MODIFIED="1495544331">Test Folder 1 (Tier 1)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495544331" LAST_MODIFIED="1495546321">Test 1 (Tier 2)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495546129" LAST_MODIFIED="1495546445">Test 1 (Tier 3)</H3>
<DL><p>
<DT><A HREF="https://stackoverflow.com/" ADD_DATE="1495546321" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABXklEQVQ4jbWQsUsCYRjGn/fuSu/Sk3ALmlzNtoagKRqSaHMKGkKhEOV0KWispSXPQaglAnNobOgfaCyIcgicmxO9zFPv/N5WwTs5gt7x+5739/2eDwgw/bK67HcnBQG4Ag3L0LJ/BoBFDuDzTiGUCAywDC3bNbRtANCrwxaBziRZanAGcjADwR8AX1uGesEZyFGzXwO43VsKn07GaJa5lY/GMefUAYooEvaELDnCEW9M2I1V7GdPg04hlLAM7dYqqut67ftLNwdpMB5dgRfXdVMgHIFpx9egfbwYk0eDA2LKAWJMkK6cUOhOGdkpZmoQiy29OmwFq1AKb5CgQyakAXqQJKpELn/eJzPK1JKhPhHjk4EmMzUVmU/coVLkeXff672pk155YXUsxikCJQFeYVCSgCiAV920N311b+r37FslH413S+qaV86rggfIBbG38RRAN+2ZHzsTMKvGv80vvziHGAusG84AAAAASUVORK5CYII=">Stack Overflow</A>
<DT><A HREF="https://dirtymarkup.com/" ADD_DATE="1495546340" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACC0lEQVQ4jc2SO4gTYRSFz//feWWSaHQnM2GHTZNNlS67bGFlvYXaLWhnp5WNnZ2dnaxopZVgZWElbGO/6EAkJIWGQBhI3BnMY9U89n/YZCGKBGzEAwducc6Fy/2AfyT+N2G29J9Ev8+0JgwADgCxu7u7FwTBYjAYfFt29NJgAEwAZwBQq9UuM8YCItpoNBrHtVrNYoxdchznaLFY3BBCyFar9XnlLEUAlOd5+a2tLa/dbo/CMLzPOb/S7/ffJEkyD8PwJmPMVkp9NAxjr1gs5kulkmPbtjRN0+QATM/zNizLqtbr9UeMsarW+jEAtbm56QI4mM/nTwzDKBiGcZuI9pVSwnVdnqbplJfL5RwRzSzLeqm1nkZRdD2O4w4AXSqVDojIbjabx1EUHU0mk2tElLMs63A2m0kAnPd6vWGapqda64ec8+2dnZ27vu8DAOOc35FSPgOggiDIZLPZUGt9UWv9XWudKRQKLhWLxZzrunkiOmGMCSLaJyLm+77POb8aRdE9AKpard4iogdSyhcAXnHOEcfxFyNJkkU2mx0JIc6klO+klLHW+oPjOK+VUs8BKAAmY6wuhDhsNBpvK5XKhU6nkwBgBECORiOZpumPNE2/5nK5k+l0qmzb3h6Px0+Hw6ECgEwm8940zU+u64put3u65MBcpe8crFXaAMBa/nwdcL+wfr5gbeH/0U9As88ACmZhwgAAAABJRU5ErkJggg==">DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code</A>
<DT><A HREF="http://www.bbc.com/news" ADD_DATE="1495546445" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAT0lEQVQ4je2RMQ7AIAwDz/z/z+5QgajJUmXlxkO2kQIXAe7kB4Bt7G9P5So/VpV0BNLZRhKSzoL5mGvpkl8/qNA75BXY19MVXu0rNLKXyQMkVzL9n5I6iQAAAABJRU5ErkJggg==">Home - BBC News</A>
</DL><p>
</DL><p>
</DL><p>
<DT><H3 ADD_DATE="1495546969" LAST_MODIFIED="1495546987">Test Folder 2 (Tier 1)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495546987" LAST_MODIFIED="1495547012">Test 2 (Tier 2)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495547012" LAST_MODIFIED="1495547167">Test 2 (Tier 3)</H3>
<DL><p>
<DT><A HREF="https://stackoverflow.com/" ADD_DATE="1495547167" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABXklEQVQ4jbWQsUsCYRjGn/fuSu/Sk3ALmlzNtoagKRqSaHMKGkKhEOV0KWispSXPQaglAnNobOgfaCyIcgicmxO9zFPv/N5WwTs5gt7x+5739/2eDwgw/bK67HcnBQG4Ag3L0LJ/BoBFDuDzTiGUCAywDC3bNbRtANCrwxaBziRZanAGcjADwR8AX1uGesEZyFGzXwO43VsKn07GaJa5lY/GMefUAYooEvaELDnCEW9M2I1V7GdPg04hlLAM7dYqqut67ftLNwdpMB5dgRfXdVMgHIFpx9egfbwYk0eDA2LKAWJMkK6cUOhOGdkpZmoQiy29OmwFq1AKb5CgQyakAXqQJKpELn/eJzPK1JKhPhHjk4EmMzUVmU/coVLkeXff672pk155YXUsxikCJQFeYVCSgCiAV920N311b+r37FslH413S+qaV86rggfIBbG38RRAN+2ZHzsTMKvGv80vvziHGAusG84AAAAASUVORK5CYII=">Stack Overflow</A>
<DT><A HREF="https://dirtymarkup.com/" ADD_DATE="1495547167" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACC0lEQVQ4jc2SO4gTYRSFz//feWWSaHQnM2GHTZNNlS67bGFlvYXaLWhnp5WNnZ2dnaxopZVgZWElbGO/6EAkJIWGQBhI3BnMY9U89n/YZCGKBGzEAwducc6Fy/2AfyT+N2G29J9Ev8+0JgwADgCxu7u7FwTBYjAYfFt29NJgAEwAZwBQq9UuM8YCItpoNBrHtVrNYoxdchznaLFY3BBCyFar9XnlLEUAlOd5+a2tLa/dbo/CMLzPOb/S7/ffJEkyD8PwJmPMVkp9NAxjr1gs5kulkmPbtjRN0+QATM/zNizLqtbr9UeMsarW+jEAtbm56QI4mM/nTwzDKBiGcZuI9pVSwnVdnqbplJfL5RwRzSzLeqm1nkZRdD2O4w4AXSqVDojIbjabx1EUHU0mk2tElLMs63A2m0kAnPd6vWGapqda64ec8+2dnZ27vu8DAOOc35FSPgOggiDIZLPZUGt9UWv9XWudKRQKLhWLxZzrunkiOmGMCSLaJyLm+77POb8aRdE9AKpard4iogdSyhcAXnHOEcfxFyNJkkU2mx0JIc6klO+klLHW+oPjOK+VUs8BKAAmY6wuhDhsNBpvK5XKhU6nkwBgBECORiOZpumPNE2/5nK5k+l0qmzb3h6Px0+Hw6ECgEwm8940zU+u64put3u65MBcpe8crFXaAMBa/nwdcL+wfr5gbeH/0U9As88ACmZhwgAAAABJRU5ErkJggg==">DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code</A>
<DT><A HREF="http://www.bbc.com/news" ADD_DATE="1495547167" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAT0lEQVQ4je2RMQ7AIAwDz/z/z+5QgajJUmXlxkO2kQIXAe7kB4Bt7G9P5So/VpV0BNLZRhKSzoL5mGvpkl8/qNA75BXY19MVXu0rNLKXyQMkVzL9n5I6iQAAAABJRU5ErkJggg==">Home - BBC News</A>
</DL><p>
</DL><p>
</DL><p>
<DT><H3 ADD_DATE="1495547034" LAST_MODIFIED="1495547056">Test Folder 3 (Tier 1)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495547056" LAST_MODIFIED="1495547084">Test 3 (Tier 2)</H3>
<DL><p>
<DT><H3 ADD_DATE="1495547084" LAST_MODIFIED="1495547171">Test 3 (Tier 3)</H3>
<DL><p>
<DT><A HREF="https://stackoverflow.com/" ADD_DATE="1495547171" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABXklEQVQ4jbWQsUsCYRjGn/fuSu/Sk3ALmlzNtoagKRqSaHMKGkKhEOV0KWispSXPQaglAnNobOgfaCyIcgicmxO9zFPv/N5WwTs5gt7x+5739/2eDwgw/bK67HcnBQG4Ag3L0LJ/BoBFDuDzTiGUCAywDC3bNbRtANCrwxaBziRZanAGcjADwR8AX1uGesEZyFGzXwO43VsKn07GaJa5lY/GMefUAYooEvaELDnCEW9M2I1V7GdPg04hlLAM7dYqqut67ftLNwdpMB5dgRfXdVMgHIFpx9egfbwYk0eDA2LKAWJMkK6cUOhOGdkpZmoQiy29OmwFq1AKb5CgQyakAXqQJKpELn/eJzPK1JKhPhHjk4EmMzUVmU/coVLkeXff672pk155YXUsxikCJQFeYVCSgCiAV920N311b+r37FslH413S+qaV86rggfIBbG38RRAN+2ZHzsTMKvGv80vvziHGAusG84AAAAASUVORK5CYII=">Stack Overflow</A>
<DT><A HREF="https://dirtymarkup.com/" ADD_DATE="1495547171" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACC0lEQVQ4jc2SO4gTYRSFz//feWWSaHQnM2GHTZNNlS67bGFlvYXaLWhnp5WNnZ2dnaxopZVgZWElbGO/6EAkJIWGQBhI3BnMY9U89n/YZCGKBGzEAwducc6Fy/2AfyT+N2G29J9Ev8+0JgwADgCxu7u7FwTBYjAYfFt29NJgAEwAZwBQq9UuM8YCItpoNBrHtVrNYoxdchznaLFY3BBCyFar9XnlLEUAlOd5+a2tLa/dbo/CMLzPOb/S7/ffJEkyD8PwJmPMVkp9NAxjr1gs5kulkmPbtjRN0+QATM/zNizLqtbr9UeMsarW+jEAtbm56QI4mM/nTwzDKBiGcZuI9pVSwnVdnqbplJfL5RwRzSzLeqm1nkZRdD2O4w4AXSqVDojIbjabx1EUHU0mk2tElLMs63A2m0kAnPd6vWGapqda64ec8+2dnZ27vu8DAOOc35FSPgOggiDIZLPZUGt9UWv9XWudKRQKLhWLxZzrunkiOmGMCSLaJyLm+77POb8aRdE9AKpard4iogdSyhcAXnHOEcfxFyNJkkU2mx0JIc6klO+klLHW+oPjOK+VUs8BKAAmY6wuhDhsNBpvK5XKhU6nkwBgBECORiOZpumPNE2/5nK5k+l0qmzb3h6Px0+Hw6ECgEwm8940zU+u64put3u65MBcpe8crFXaAMBa/nwdcL+wfr5gbeH/0U9As88ACmZhwgAAAABJRU5ErkJggg==">DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code</A>
<DT><A HREF="http://www.bbc.com/news" ADD_DATE="1495547171" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAT0lEQVQ4je2RMQ7AIAwDz/z/z+5QgajJUmXlxkO2kQIXAe7kB4Bt7G9P5So/VpV0BNLZRhKSzoL5mGvpkl8/qNA75BXY19MVXu0rNLKXyQMkVzL9n5I6iQAAAABJRU5ErkJggg==">Home - BBC News</A>
</DL><p>
</DL><p>
</DL><p>
</DL><p>
</DL><p>

输出

Test Folder 1 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://stackoverflow.com/
Stack Overflow

Test Folder 1 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://dirtymarkup.com/
DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code

Test Folder 1 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
http://www.bbc.com/news
Home - BBC News


Test Folder 2 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://stackoverflow.com/
Stack Overflow

Test Folder 2 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://dirtymarkup.com/
DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code

Test Folder 2 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
http://www.bbc.com/news
Home - BBC News


Test Folder 3 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://stackoverflow.com/
Stack Overflow

Test Folder 3 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
https://dirtymarkup.com/
DirtyMarkup · Tidy up your HTML, CSS, and JavaScript code

Test Folder 3 (Tier 1)
Test 1 (Tier 2)
Test 1 (Tier 3)
http://www.bbc.com/news
Home - BBC News

最佳答案

var map = { };

$('Break').children().each(function(_, node) {
map[ _ ] = { };
map[ _ ][ node.nodeName ] = node.textContent;
});

这是完成的第一部分。但我卡在数组部分....

关于javascript - 操作 HTML 并放入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44144228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com