英文:
Get html table data from html page and retrive from specific format
问题
I have following html page of gujarat board student result. in this pages student result data store in html table. all the result data get in following format.
https://gseb.org/522lacigam/sci/B24/06/B240661.html
Result Format can i get all result data from html table in specific format.
英文:
I have follwing html page of gujarat board student result. in this pages student result data store in html table. all the result data get in follwing format.
https://gseb.org/522lacigam/sci/B24/06/B240661.html
Result Format can i get all result data from html tabel in specific format.
答案1
得分: 1
- 首先,您需要从 http://simplehtmldom.sourceforge.net/ 下载简单的HTML DOM解析库,并将其包含在您的PHP脚本中:
include('simple_html_dom.php');
- 接下来,您可以使用该库加载来自URL的HTML文档并查找包含结果数据的表元素:
$url = 'https://gseb.org/522lacigam/sci/B24/06/B240661.html';
$html = file_get_html($url);
$table = $html->find('table', 0);
- 一旦您拥有表元素,您可以遍历其行并从每个单元格中提取数据:
$data = array();
foreach ($table->find('tr') as $row) {
$rowData = array();
foreach ($row->find('td') as $cell) {
$rowData[] = $cell->plaintext;
}
$data[] = $rowData;
}
请注意,以上代码示例是根据您提供的内容进行的翻译。如果您需要更多帮助或有其他问题,请随时提问。
英文:
-
first you need to download the simple HTML DOM parse library from http://simplehtmldom.sourceforge.net/ and include it in your PHP script
include('simple_html_dom.php');
-
Next, you can use the library to load the HTML document from the URL and find the table element that contains the result data.
$url = 'https://gseb.org/522lacigam/sci/B24/06/B240661.html';
$html = file_get_html($url);$table = $html->find('table', 0);
-
Once you have the table element, you can iterate over its rows and extract the data from each cell.
$data = array(); foreach ($table->find('tr') as $row) { $rowData = array(); foreach ($row->find('td') as $cell) { $rowData[] = $cell->plaintext; } $data[] = $rowData;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论