[英]reading a webpage html source code and adding table into arrays with php
im trying to read a webpage's source code and add an information of a table into arrays 我试图阅读网页的源代码并将表的信息添加到数组中
The webpage is http://dsrd.uc.cl/dara/libcursos/periodo21/ua5_1.html 该网页是http://dsrd.uc.cl/dara/libcursos/periodo21/ua5_1.html
Within the table, i want to add the column "profesores" into an array profesores[] and the column "nombre asignatura" into an array curso[]; 在表格中,我想将列“profesores”添加到数组profesores []和列“nombre asignatura”到数组curso [];
I know I can get the webpage source coude with: 我知道我可以通过以下方式获取网页来源:
$homepage = file_get_contents('http://www.example.com/');
but I have no idea into how to manage the string to create the arrays. 但我不知道如何管理字符串来创建数组。
One way would be to use DOMDocument: 一种方法是使用DOMDocument:
$doc = new DOMDocument(); $doc->loadHTML($homepage); $table = $doc->getElementsByTagName("table")->item(/* Find out which one it is */) $rows = $table->getElementByTagName("tr") for ($i = 0; $i length; $i++) { $row = $rows->item($i); /* Find columns and add it to your array */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.