如何将 HTML 表格转换为 csv 格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2627162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert an HTML table to csv format?
提问by wefwgeweg
Is there an HTML parser or some library that automatically converts HTML tables into CSV data rows?
是否有 HTML 解析器或一些库可以自动将 HTML 表转换为 CSV 数据行?
采纳答案by deklin
Here issome perl script. And online converter(java needed). Or you can just manually copy HTML table from browser to OpenOffice Calc / MS Excel and save it as CSV - this will worktoo.
这是一些 perl 脚本。和在线转换器(需要java)。或者您可以手动将 HTML 表格从浏览器复制到 OpenOffice Calc / MS Excel 并将其另存为 CSV - 这也可以。
And hereyou are step-by-step solution on PHP.
这里是 PHP 的分步解决方案。
回答by Rohit Galgalikar
sed s/'<td>'//g d1.txt | sed s/'<\/td>'//g | sed s/'<\/a>'/'<\/a>,'/g | sed s/'<\/em>'/'<\/em>,'/g | sed s/'<tr>'/'<br>'/g | sed s/'<\/tr>'//g | sed s/'<th>'/'<b>'/g | sed s/'<\/th>'/'| <\/b>'/g> names1.html
sed s/'<td>'//g d1.txt | sed s/'<\/td>'//g | sed s/'<\/a>'/'<\/a>,'/g | sed s/'<\/em>'/'<\/em>,'/g | sed s/'<tr>'/'<br>'/g | sed s/'<\/tr>'//g | sed s/'<th>'/'<b>'/g | sed s/'<\/th>'/'| <\/b>'/g> names1.html
回答by M.S.
you can try this simple PHP script (also as online converter) http://www.scherello.de/?id=243
你可以试试这个简单的 PHP 脚本(也可以作为在线转换器) http://www.scherello.de/?id=243