[英]Get table value using PHP Simple HTML DOM
I'm writing this PHP to read the data from the following website, and the write it into database. 我正在编写此PHP,以从以下网站读取数据,并将其写入数据库。
Here's the code: 这是代码:
<?php
require('simple_html_dom.php');
$html = file_get_html('http://backpack.tf/pricelist/spreadsheet');
$data = $html->find('.table tr td[1]');
foreach($data as $result)
{
echo $result->plaintext . '<br />';
}
?>
I intended to get all the data in the tds and even the attribute inside the trs. 我打算在tds中获取所有数据,甚至在trs中获取属性。
So, I tried by getting them in plain text first. 因此,我尝试首先将它们以纯文本格式提供。 By far the code returns:
到目前为止,代码返回:
Fatal error: Call to a member function find() on a non-object
致命错误:在非对象上调用成员函数find()
How can I solve and improve the code? 如何解决和改进代码?
The following code is working for your example. 以下代码适用于您的示例。 It could be the memory limit for your executing script that's causing trouble.
可能是正在执行的脚本的内存限制引起了麻烦。
ini_set('memory_limit','160M');
require('simple_html_dom.php');
$url = 'http://backpack.tf/pricelist/spreadsheet';
$html = new simple_html_dom();
$html->load_file($url);
$data = $html->find('.table tr td[1]');
foreach($data as $result)
{
echo $result->plaintext . '<br />';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.