此代码将下载 html 文件中的表格:我从这里获取它:http://www.kunalbabre.com/projects/table2CSV.php
<form action="getcsv.php" method ="post" >
<input type="hidden" name="csv_text" id="csv_text"/>
<input type="submit" value="Get CSV File" onclick="getCSVData()">
</form>
<script>
function getCSVData(){
var csv_value=$('#example1').table2CSV({delivery:'value'});
//$("#csv_text").val(csv_value);
}
</script>
getcsv.php:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
$data=stripcslashes($_REQUEST['csv_text']);
echo $data;
?>
但是,我正在提取的表格是分页的。 我只能拿到第一页。 如何将表中的所有数据包含在 csv 中?
分页表格如下所示:
<div id="paging_container8">
<div class="page_navigation">
</div>
<table id="my-table">
<tr style="display: table-row;">
<tr style="display: table-row;">
<tr style="display: none;"> // next page (paginated)
<tr style="display: none;"> //next page (paginated)
</table>
<div class="page_navigation">
</div>
<br>
</div>
最佳答案
您仅将最近的站点表内容粘贴到 csv 中: 这个 JavaScript:
var csv_value=$('#example1').table2CSV({delivery:'value'});
//$("#csv_text").val(csv_value);
和 PHP:
$data=stripcslashes($_REQUEST['csv_text']);
您的 JavaScript 只会读取最近的 html 页面中的数据,因此您只能获取它们。
这是最好的解决方案: 更改您的 php 文件以获取所有表站点的所有数据。
关于php - HTML 表格转为 CSV,包括分页行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16707116/