{"id":3347,"date":"2023-08-21T15:46:59","date_gmt":"2023-08-21T07:46:59","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=3347"},"modified":"2023-08-21T15:46:59","modified_gmt":"2023-08-21T07:46:59","slug":"html%e8%bd%acexe-linux%e7%b3%bb%e7%bb%9f%e6%93%8d%e4%bd%9c%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/3347\/","title":{"rendered":"html\u8f6cexe linux\u7cfb\u7edf\u64cd\u4f5c\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

HTML\u8f6cExcel\u662f\u4e00\u79cd\u975e\u5e38\u5e38\u89c1\u7684\u6570\u636e\u8f6c\u6362\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u5c06HTMLexe\u9006\u5411\u5de5\u5177<\/a>\u683c\u5f0f\u7684\u6570\u636e\u8f6c\u6362\u4e3aExcel\u8868\u683c\uff0c\u65b9\u4fbf\u7528<\/p>\n

<\/figure>\n<\/p>\n

\u6237\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u5728Linux\u7cfb\u7edf\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7b49\u7f16\u7a0b\u8bed\u8a00\u5b9e\u73b0HTML\u8f6cExcel\u7684\u529f\u80fd\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981exe\u8f6f\u4ef6\u591a\u5f00<\/a>\u4e86\u89e3HTML\u548cExcel\u7684\u57fa\u672c\u7ed3\u6784\u548c\u8bed\u6cd5\u3002HTML\u662f\u4e00\u79cd\u7528\u4e8e\u521b\u5efa\u7f51\u9875\u7684\u6807\u8bb0\u8bed\u8a00\uff0c\u5b83\u4f7f\u7528\u6807\u7b7e\u548c\u5c5e\u6027\u6765\u63cf\u8ff0\u7f51\u9875\u7684\u7ed3\u6784\u548c\u5185\u5bb9\u3002Excel\u662f\u4e00\u79cd\u7535\u5b50\u8868\u683c\u8f6f\u4ef6\uff0c\u5b83\u4f7f\u7528\u5355\u5143\u683c\u6765\u5b58\u50a8\u6570\u636e\uff0c\u5e76\u5141\u8bb8\u7528\u6237\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3001\u8fc7\u6ee4\u548c\u8ba1\u7b97\u7b49\u64cd\u4f5c\u3002<\/p>\n

\u5728Linux\u7cfb\u7edf\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684pandas\u5e93\u6765\u5b9e\u73b0HTML\u8f6cExcel\u7684\u529f\u80fd\u3002pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u51fd\u6570\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u5404\u79cd\u6570\u636e\u683c\u5f0f\u3002<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684HTML\u8f6cExcel\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n

“`python<\/p>\n

import pandas as pd<\/p>\n

# \u8bfb\u53d6HTML\u6570\u636e<\/p>\n

html_data = pd.read_html(‘http:\/\/example.com\/table.html’)<\/p>\n

# \u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame\u683c\u5f0f<\/p>\n

df = pd.DataFrame(html_data[0])<\/p>\n

# \u4fdd\u5b58\u4e3aExcel\u6587\u4ef6<\/p>\n

df.to_excel(‘table.xlsx’, index=False)<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528pandas\u7684read_html\u51fd\u6570\u8bfb\u53d6HTML\u6570\u636e\uff0c\u7136\u540e\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame\u683c\u5f0f\uff0c\u6700\u540e\u4f7f\u7528to_excel\u51fd\u6570\u5c06\u6570\u636e\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528index\u53c2\u6570\u6765\u63a7\u5236\u662f\u5426\u4fdd\u5b58\u7d22\u5f15\u5217\u3002<\/p>\n

\u9664\u4e86\u4f7f\u7528pandas\u5e93\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7684\u6570\u636e\u5904\u7406\u5e93\u6765\u5b9e\u73b0HTML\u8f6cExcel\u7684\u529f\u80fd\uff0c\u6bd4\u5982xlwt\u3001openpyxl\u7b49\u5e93\u3002\u8fd9\u4e9b\u5e93\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u5904\u7406\u51fd\u6570\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u6570\u636e\u8f6c\u6362\u9700\u6c42\u3002<\/p>\n

\u603b\u4e4b\uff0c\u5728Linux\u7cfb\u7edf\u4e0a\u5b9e\u73b0HTML\u8f6cExcel\u7684\u529f\u80fd\uff0c\u9700\u8981\u6211\u4eec\u719f\u6089HTML\u548cExcel\u7684\u57fa\u672c\u8bed\u6cd5\u548c\u7ed3\u6784\uff0c\u4ee5\u53ca\u638c\u63e1\u4e00\u4e9b\u6570\u636e\u5904\u7406\u5e93\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\u53ea\u8981\u638c\u63e1\u4e86\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u5c31\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u5404\u79cd\u6570\u636e\u8f6c\u6362\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML\u8f6cExcel\u662f\u4e00\u79cd\u975e\u5e38\u5e38\u89c1\u7684\u6570\u636e\u8f6c\u6362\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u5c06HTML\u683c\u5f0f\u7684\u6570\u636e\u8f6c\u6362\u4e3aExcel\u8868\u683c\uff0c\u65b9\u4fbf\u7528\u6237\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u5728Linux\u7cfb\u7edf\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7b49\u7f16\u7a0b\u8bed\u8a00\u5b9e\u73b0HTML\u8f6cEx<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[1001,6727,168,2319,291],"topic":[],"class_list":["post-3347","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-exe","tag-htmlexe","tag-168","tag-2319","tag-291"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=3347"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3347\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=3347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=3347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=3347"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=3347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}