我想創建一個Python程序,將採取一個html文件的完整我的書籤,閱讀其內容,刪除除我想要把一切都在一個文件中刪除,並保存剩餘部分只包含每個條目的URL和網頁名稱。如何定義如何使用Python
我設法讓Python打開,並通過HTML文件中讀取其內容存儲在一個.csv文件,但我不知道如何告訴它刪除某些部分,並保持休息。例如,我有一個名爲「February」的子文件夾,我只想將該文件夾的內容放入CSV文件中。在這些內容中,我只想在該「二月」文件夾中存儲所有已加入書籤的網站的網址和網頁名稱。
我只想着如何辨別什麼,保持什麼去除是lstrip()方法,但幾乎不起作用知識。我的編程詞彙量也很差,所以我不知道如何「正式」描述我想要做什麼,從而使我的幫助變得更加困難。
任何人都可以幫我嗎?我目前處於全面虧損狀態。
編輯:包括所有我到目前爲止的代碼:
with open("bookmarks_3_6_17.html",'r',errors='ignore') as file:
content=file.read()
#Gets the contents of the bookmarks html file
with open("bookmarks.csv",'w') as file:
file.write(content)
file.seek(0)
file.lstrip('<DT>')
編輯2:下面是一些我想使用的代碼示例。比方說,從HTML文件中的「食品」書籤文件夾,我想只有「意大利麪」子文件夾中的內容到.csv文件,以及這些內容,我只想要得到的網址和網頁名稱每個書籤頁。
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1417261149" LAST_MODIFIED="1488711452">Foods</H3>
<DL><p>
<DT><H3 ADD_DATE="1480251437" LAST_MODIFIED="1483641856">Pasta</H3>
<DL><p>
<DT><A HREF="http://paleoleap.com/quick-and-easy-paleo-stir-fries/" ADD_DATE="1423327839" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwklEQVQ4jb2TzUvUQRjHv8/Mb90XNRISERcVgoQOkYcUIruIJot7/AlbawcDTxb9AQXzD3gxCALBaJHQFSKIyMAXUNGLiCAqJKEXhTRaf2y76748TwczdlddvOTnNsN8P/PMPDPApSNGAaCTIZVYWpqZEQ+SNXKegCACEMm/GdvWiEZzV6bHAoqpD5lMCwjLF6vAGAVj+PpU9O4vrRfEUwb8TkAyucdnCnxfIrVKy1XOUSzR1bsHAGX9vXbHneYHq411fsdSTJns4GFnaOq0YPJdeZVYO3BZ6/B5Y4gnqo5GP3wVy3Xovt30MTbwYif/qKoorrD4PQmPO867P+bSkYl5Ityz2tu2ksORoYKwMQqA5AsIAOMmLF7bVLyydot3f84K0YH2VzfAtjXe9LvyBHwc+nu7AFAeDnWQ5h59vzVIDf5R0uoGKXJlndRTJ/joGwQEgqBoV1SGgtfEU/kSIpL1eoe8Pd2f5Sj9iTk74QTCS6UapHx9D5+Iu+IVi8zE375/nnpdv410ql5INpxAeAnj4xpy/oOzwOwH5Z4lRqL7AAhkRCbHutKKtiFCIGKgsOyzMSjuyAWxbX1aVvhh/it/AC9/rLpQgLvvAAAAAElFTkSuQmCC">Quick And Easy Paleo Stir-Fries | Paleo Leap</A>
<DT><A HREF="http://allrecipes.com/recipe/11951/linguine-with-clam-sauce/" ADD_DATE="1480251695" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC/ElEQVQ4jW2TTWhcZRSG3/d8352fzGQmSWMsbVoTaK1ahEBERQqCgrgR3PgD1k3VkoIrxUV32YngphXFSLMSC1pcuLBCQIuIfyvtJhFtKG3S2kZIk0lm7r1zv/u9LlKLoIuzO5z3cM7zEAAEkIAA4Orxe5/14NHgdcSP2lhMlWNTSxE6n3f14cFPLq3+u5+3S9eP7xmVDb5vxPMeRJwA/F6nmIrlUkSSAn1opSjCW/vPLH86C9gsECmAq6+MDzNpLLSqbnqjF0pWTbUpOhhpCZVfDiquoKxUkVTM0OmHmcmP/pgTQCOg6Bun2omm17ezviSTgqcRgCQAMBjK4ENkyPIs1oj3lo8deoiAbHXm8BMu9F/acoMhaY96OKO5QcVeSZoRUVSPYrPNmKc+tnbHequdeBdmAcCHdPPV4Yn70XjjLJRuU9mW0t9/Zeerk6hP70JYyxDTNnefPKvixjLqh4+47YV5xXNvP/nnm488YCiyxypPvQaUhd08dYy2a5yuPYLwl1CuC8W1EiiJZM8B2sAg1t55QZ0LH6veaNWKrY3HjfXmPtv/INOL3zC/eEHZ0vegTwBFKAiIAoyIWRe3Pn+X6dKPjN1OWUucgLjX4BKwOoDY3QS9h8oAkQABJgQdQBqkCJjB6i3AHLBzXphJKx4SSIkkyTtw0AtwhCSQhBGCSkFyWRQRdc1CuvUDe+v0o+NR/UJu6G4pFIBxZwPPnbAYtfNU0gjmQZkcvrXy6s0znZ+/VP3hZ3jX6x+oduhRkib9M8AJBooDLYKOUiwbidGAr++Zu7ToTl/B5RMjKweGmvWpYnCs6P30heUriww3FlWZqCJuC2E90lUS5YvflVakJljIiuLl07/cur6D8nOtYdUGFtpVP71RxBLwciN1V51yLNek/LdCKLOyUq0nlcSjk/ZnJueX76CMfec6637svqe3K63PKs0hN9BoeBI0R0Fi4pw1W62E5le6Wf/FyfnluVnACIj/q7PxaNBtnXvK0dVSNJ7Pt8r/6Pw3hFGRINul+ukAAAAASUVORK5CYII=">Linguine with Clam Sauce Recipe - Allrecipes.com</A>
<DT><A HREF="http://www.food.com/recipe/tuscan-vegetarian-pasta-392763?photo=376155" ADD_DATE="1480251701" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB40lEQVQ4jXWRQWtTURCFv7kvTRDrQkUotQU3UuNCGmOVGOtC7U+IbtwaRLf+CNFFxdK6F9x0L4I1Klh9aYgtCoV25bMktSk0C0mtafLuuLAvfWnzDlzuzNxzDjNzhRDS6XSfSSTu+qo5MCmDnrBI3ai/qDD7tVh8BbTDGgmC0bGro06MWSNylgj4fnsVuL24sPC9yyB1OXvJcexHEXM0ShxAfb+Bketl110CkKFM5sgpkdUYMhyQ5j8UiMfjXcJms8n4jVsAWFVv69d60vO8v7EBNfdFGA6T4/E4Gxs15gqFfYPd3U5sRM6cHBi853neVAxt5yB2qNVKtcrUzIvIUYxoDpgyQLInwUivcgfq6zkAY42T6EW4mEpR+vypc8avZbverWMMQEzQHyDnDxrUNjeZe7e/g59ra90dIit7BrwGDhlUq1WeT89EjiDwHsDswOO2ai2SCUzmW0zmW53cV/39B/sMwCy7bt2xPAwLms1m17cBqAa3Wkclv+y69b1O/mMsk3mkyBMRiVy/qt0GHpRd92VQc4JgvVL5Mjh0umQxN43Q30P8tgUTS647H66bcFIuFt/Yne2kqn2qvt8Iv4lK6ZvrVg8aR7Y7MpI91n+cO4idEF+uIH5fQ/XCSqm0Feb9A49dxB4CHUbcAAAAAElFTkSuQmCC">Tuscan Vegetarian Pasta Recipe - Food.com: Food.com</A>
<DT><A HREF="http://www.cheatsheet.com/life/8-deliciously-rustic-pasta-recipes-no-tomato-sauce-required.html/?a=viewall" ADD_DATE="1480251706" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB9klEQVQ4jZXTP2hTURTH8e/Ly9+iMbV0V1BxsViFGKji5l+wWnBQCkKXRItukVaHCg7SIUMnKbXqUkVQaZSCJHVT1MHSUKKgnQoprSR9af73vftyHSqP/HkUPNO9HPhw7u9wFSmlpKWklCxnfpLaeNPaAkBVXFw5MgKAYgfEJqZxdmp8JoqUShvgVr3MDFYAcDY2TNMkNjHFq9dzjN6NMH7qO9AMPP4UZkVLW3cLqNfrjD2MEX//YbvhUNnfdYxyuYKWL+DxuOna24lKB8KgHXgbf8f6n1WCx3tAgVqtRvTeI75+W2RL1wG4OnABZZ8bodsAyeIYhy71Ej33nMzqGkORETRtk1Cwl1DwKIViicMHDzC3/sJ+gkx2hV2ubgAmn7xE0zYZvHaZO7duNGUwOyObAIcVoAGm2F7hQiqNlJKB/jOtC8AUij0g/gFCmOS1HIZRxef12gDsDLhcTvb4O6hWivz6vfz/AMDpk0H0WonR+w9YTC0hhKBSqVAoFDFNaR9iI3B7OEw6nSaRmOf8xX78fj+6rjMcCSM9qv0aGwGfz8uz6UkSySTz8x/J5TYIBAL09Z1g6UscIWwA05Dk8jmSC7NWU+2WnL0esu4luUY2n8VseIL1mXpu7qa6VW4Lza5cqpsfU7XmCcaHnmI00juU6lCt81+o9fbXm9GQegAAAABJRU5ErkJggg==">8 Deliciously Rustic Pasta Recipes, No Tomato Sauce Required</A>
<DT><A HREF="http://www.foodnetwork.com/recipes/giada-de-laurentiis/penne-with-sun-dried-tomato-pesto-recipe.html" ADD_DATE="1480251830" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADQUlEQVQ4jXWTTWxUZRSG3++7987cdv6AsWJt7lw7koC21bHW0DSVSBw0kiYaEmigbTBmHEOKPywkIGBwY2LiwgRKHWxMXEgMC1ZdScUYaiWBwEjSwqCddiqdtg6Ytre3M/fvOy5KK8Z4kndz8r7nnMV5GAAQEWOMEQAsjd5ImN8OpJavDrc7xYknGONCrtWn1Bfah0NdqYFgw3PZf2WIiOFBzZ388HS+sY6K9aAJHXQntqIJHVSsB43roNkTB0+t+omIrYWnUnsuqpfOJ0suF1ziHhdCAj0wAiCJe9wT0gZZ8PKLHd/Hvhl8FQD4yuYj/f4fzieXtu+vRI6e5jysKSQEJxIcjDjzhTn3XIVI8PshraJeHnxl7RLzt7Hm33VQ4dgR2zVNWshm6ZYGuq2Bck0a3dZAtzRQrt5HuS01NKqBcluf8txikci2E9y4cOEdPwOiPW8KI5vFZEcC6u73ILXshDv/B3hdA6o6PwC5NsgsQW19HRtOfOZwVcXsyUMp2bz4XVtV91EENm9WFm/+isczgwg0NgEk8OfZL/FIz35IkXUwticB8hBseAZyNKqYV0ZgXB1u53YhH7cWFyAsi5fHxhBqaUGhXYe3vIzH3j+E8p0cip8cR2RrK4JNCUxtq4c9MwNzehruTCHGAYCHwnCWlmBP5gECqt/+GHIoDFGxIFwX6/d2wzUMAIB/Vy+qN22CVyqBA+CKHs+HE82A5wrzzHGUx8cR3deNuTOnMPfF5wgkmgFJwvS+N+DcKyGyey8Wr1+DLxiAr1afYncPpzO13b3psiJbkzsa/L6nt4HJClAdAJcViPIyyJgHC4bBN9ZC3C3Azv1srSPbL/e82yc/2nvsLKupSc9/1c8ZAPXl1+DTNJBlwyuVoDwZh1hYBHkOhOMBWxrhjv6kWOE6RDrfGmAAMH9pKGOnkum/1GgFxn0V/1MEgKlqJSpsVXQe6Nv4ad/Bf165q+PHql8GX7oHxYHMBbddhSA4k6oFiQpIkR3mQYmSxcutyaHYuaEda0CsDpk9nM6sgjOhg3KxFa328jpo7qMD/f+B6WGczZtXnjfOfZ02r420OYV8HAAUPZ4PNLeNhLrSmcCzLdcfzvwNewmTrcvJYeoAAAAASUVORK5CYII=">Penne with Sun-Dried Tomato Pesto Recipe : Giada De Laurentiis : Food Network</A>
<DT><A HREF="http://www.simplyrecipes.com/recipes/mediterranean_tuna_pasta/" ADD_DATE="1480329433">Mediterranean Tuna Pasta Recipe | SimplyRecipes.com</A>
</DL><p>
<DT><H3 ADD_DATE="1480251449" LAST_MODIFIED="1485183080">Chicken</H3>
<DL><p>
<DT><A HREF="http://www.food.com/recipe/chicken-rice-and-spices-bake-105104" ADD_DATE="1476195335" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB40lEQVQ4jXWRQWtTURCFv7kvTRDrQkUotQU3UuNCGmOVGOtC7U+IbtwaRLf+CNFFxdK6F9x0L4I1Klh9aYgtCoV25bMktSk0C0mtafLuuLAvfWnzDlzuzNxzDjNzhRDS6XSfSSTu+qo5MCmDnrBI3ai/qDD7tVh8BbTDGgmC0bGro06MWSNylgj4fnsVuL24sPC9yyB1OXvJcexHEXM0ShxAfb+Bketl110CkKFM5sgpkdUYMhyQ5j8UiMfjXcJms8n4jVsAWFVv69d60vO8v7EBNfdFGA6T4/E4Gxs15gqFfYPd3U5sRM6cHBi853neVAxt5yB2qNVKtcrUzIvIUYxoDpgyQLInwUivcgfq6zkAY42T6EW4mEpR+vypc8avZbverWMMQEzQHyDnDxrUNjeZe7e/g59ra90dIit7BrwGDhlUq1WeT89EjiDwHsDswOO2ai2SCUzmW0zmW53cV/39B/sMwCy7bt2xPAwLms1m17cBqAa3Wkclv+y69b1O/mMsk3mkyBMRiVy/qt0GHpRd92VQc4JgvVL5Mjh0umQxN43Q30P8tgUTS647H66bcFIuFt/Yne2kqn2qvt8Iv4lK6ZvrVg8aR7Y7MpI91n+cO4idEF+uIH5fQ/XCSqm0Feb9A49dxB4CHUbcAAAAAElFTkSuQmCC">Chicken, Rice, And Spices Bake Recipe - Food.com</A>
<DT><A HREF="http://chefsavvy.com/recipes/honey-barbecue-chicken-bites/" ADD_DATE="1471006227" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABlUlEQVQ4jXXTsYoUQRAG4K9mbndv98QzEc9ITTQQTMx9As0UNvc1zMQ3EAQfwFgMBF9AEAMjMVUwEBMFubvdu9kpg+69nZO1oZmuofqvv/6/Kx79XqXByqSJcu6SHoFG+Z81Xq+dbZdPkg6XgmmNT5Rvg4wNyBlA1grL5HIwn3C75WvPzbYAvF7y9pRpzVeZgUhOk308mXFvzIsFT494fsxBw622tDVsYQNQqT4Yc22HVwved1wIPna8W/JttdHhnAaJPpkFd0eser50JVZ1eLks1WY2wp4xCKySi8GVhsPkR9JWYaGNwlJsaSGqstOgzSLk6UDxHHDOc6ZXgESTHCerYNowjkJVlsp9lh3/aLABiEL9V19sutqwqtQzC+Cknre20OAQn1e0DXfaArioj+jZjPmYI/+xUZTgzQk/O+a7PByxHzyecGPE3hYGsZ6FrKItcBDcH3O95U/PfsP3ng8dnzpGsQXgTAubt7+rWNlX4FCcGg7UuWGKOn3jYKKIuE7eqzlrJ2wDWD+SddKw16xtDi/DXz9bnXlwx9EiAAAAAElFTkSuQmCC">Honey Barbecue Chicken Bites - Chef Savvy</A>
<DT><A HREF="http://www.food.com/recipe/simple-easy-stuffed-roast-chicken-with-gravy-for-beginners-101998?nl=email_share" ADD_DATE="1467453921" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB40lEQVQ4jXWRQWtTURCFv7kvTRDrQkUotQU3UuNCGmOVGOtC7U+IbtwaRLf+CNFFxdK6F9x0L4I1Klh9aYgtCoV25bMktSk0C0mtafLuuLAvfWnzDlzuzNxzDjNzhRDS6XSfSSTu+qo5MCmDnrBI3ai/qDD7tVh8BbTDGgmC0bGro06MWSNylgj4fnsVuL24sPC9yyB1OXvJcexHEXM0ShxAfb+Bketl110CkKFM5sgpkdUYMhyQ5j8UiMfjXcJms8n4jVsAWFVv69d60vO8v7EBNfdFGA6T4/E4Gxs15gqFfYPd3U5sRM6cHBi853neVAxt5yB2qNVKtcrUzIvIUYxoDpgyQLInwUivcgfq6zkAY42T6EW4mEpR+vypc8avZbverWMMQEzQHyDnDxrUNjeZe7e/g59ra90dIit7BrwGDhlUq1WeT89EjiDwHsDswOO2ai2SCUzmW0zmW53cV/39B/sMwCy7bt2xPAwLms1m17cBqAa3Wkclv+y69b1O/mMsk3mkyBMRiVy/qt0GHpRd92VQc4JgvVL5Mjh0umQxN43Q30P8tgUTS647H66bcFIuFt/Yne2kqn2qvt8Iv4lK6ZvrVg8aR7Y7MpI91n+cO4idEF+uIH5fQ/XCSqm0Feb9A49dxB4CHUbcAAAAAElFTkSuQmCC">Simple Easy Stuffed Roast Chicken With Gravy For Beginners) Recipe - Food.com</A>
<DT><A HREF="http://www.thekitchn.com/winter-casserole-recipe-simple-shepherds-pie-recipes-from-the-kitchn-179722" ADD_DATE="1480251630" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACXUlEQVQ4jYXTy2vcBRTF8c/vl5nJYyYvayJp6oNWidK6kCJWcaGo1EU3IqIWd4ESqxAQ9W8Qqc1GURfiphtFEAQ3WgQlEBFbocEX2JePtqbJJJlkHs7ruviVWG3Bszz33u/icE8SEeF6qn5O+0+kRErax8D95G7611pyDaD8HtUP0USebppBkjzRpnQvo6+QFv8D6Gxw6VVaJ8hPMniQTi07SpAWaJepfkrhNsaPkpauApx7hu4vDB4g2UH5GLFG0qF3kp4C+V307WP9HYaeZmRGDiwfo/UTo0+Qn+LSmxTvovQwlugs00mpfE1zk/7HqX12FWDlXQZ2MDLNmf307mH8JZaeJxlEjp6U4UdZ+ZiBfbQrNE5IbX5Dssrgs1Q/oXaWsVmW36JxgbEjjMzSDgoTaNO6TNKg8Z1U9XuaFfJ3UJ3PQis+QP0s7TV6Jmj9ir+yDNIWuTFaG3S6Us0ytVqWfLctixzjM1QrnNrJylF692bpt+p017PdtCQnHcyOmr9ROkDlI5aPcOPL3H6cyjzD9zC0n4vTJCUKu+j2079XTnEPSZfNRcaeoribjbnMG51h+EHWjnPmIPWvuPl1Vk8SE/RNXfmDU1MkN3D3Au0/uDxLfZ6o0U1o5cltY/sbtEucf5GJw4wfJiIill6LOHlrxO9vx5YaP0SsvR9RnouoLmTeygcRi/dF/Pzc1loG6KxGnHso4ttbIi7OxTWqfhlxfiZicXfE6UMRrfWt0T+v3F3nwjTlBQopQ49kXuM09SaxnckX2Pbk/7Sx8SOVL67UuEMnGH6M4p3Xbf3fnUpIzEG6h/4AAAAASUVORK5CYII=">Winter Casserole Recipe: Shepherd's Pie — Recipes from The Kitchn | The Kitchn</A>
<DT><A HREF="http://www.food.com/recipe/my-quot-famous-quot-shredded-chicken-205760" ADD_DATE="1485178904" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB40lEQVQ4jXWRQWtTURCFv7kvTRDrQkUotQU3UuNCGmOVGOtC7U+IbtwaRLf+CNFFxdK6F9x0L4I1Klh9aYgtCoV25bMktSk0C0mtafLuuLAvfWnzDlzuzNxzDjNzhRDS6XSfSSTu+qo5MCmDnrBI3ai/qDD7tVh8BbTDGgmC0bGro06MWSNylgj4fnsVuL24sPC9yyB1OXvJcexHEXM0ShxAfb+Bketl110CkKFM5sgpkdUYMhyQ5j8UiMfjXcJms8n4jVsAWFVv69d60vO8v7EBNfdFGA6T4/E4Gxs15gqFfYPd3U5sRM6cHBi853neVAxt5yB2qNVKtcrUzIvIUYxoDpgyQLInwUivcgfq6zkAY42T6EW4mEpR+vypc8avZbverWMMQEzQHyDnDxrUNjeZe7e/g59ra90dIit7BrwGDhlUq1WeT89EjiDwHsDswOO2ai2SCUzmW0zmW53cV/39B/sMwCy7bt2xPAwLms1m17cBqAa3Wkclv+y69b1O/mMsk3mkyBMRiVy/qt0GHpRd92VQc4JgvVL5Mjh0umQxN43Q30P8tgUTS647H66bcFIuFt/Yne2kqn2qvt8Iv4lK6ZvrVg8aR7Y7MpI91n+cO4idEF+uIH5fQ/XCSqm0Feb9A49dxB4CHUbcAAAAAElFTkSuQmCC">My famous Shredded Chicken Recipe - Food.com</A>
</DL>
相關的代碼添加到你的問題。 –
你想要一個HTML解析器。看看https://docs.python.org/2/library/htmlparser.html –
Sembei,感謝您的鏈接,我會立即檢查出來! – DangerRangerDan