从HTML页面获取HTML表格数据并以特定格式提取。

huangapple go评论53阅读模式
英文:

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

  1. 首先,您需要从 http://simplehtmldom.sourceforge.net/ 下载简单的HTML DOM解析库,并将其包含在您的PHP脚本中:
include('simple_html_dom.php');
  1. 接下来,您可以使用该库加载来自URL的HTML文档并查找包含结果数据的表元素:
$url = 'https://gseb.org/522lacigam/sci/B24/06/B240661.html';
$html = file_get_html($url);

$table = $html->find('table', 0);
  1. 一旦您拥有表元素,您可以遍历其行并从每个单元格中提取数据:
$data = array();

foreach ($table->find('tr') as $row) {
    $rowData = array();

    foreach ($row->find('td') as $cell) {
        $rowData[] = $cell->plaintext;
    }
    $data[] = $rowData;
}

请注意,以上代码示例是根据您提供的内容进行的翻译。如果您需要更多帮助或有其他问题,请随时提问。

英文:
  1. 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');


  1. 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);


  1. 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;
    

    }

huangapple
  • 本文由 发表于 2023年5月17日 11:50:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定