【发布时间】:2016-02-14 14:16:37
【问题描述】:
我正在使用 php、curl 和 simple_dom_document 从 snowbird.com 获取雪数据。问题是我似乎无法真正找到我需要的数据。我能够找到父 div 及其名称,但我找不到实际的雪信息 div。这是我的代码。在我的代码下面有一小部分输出。
<?php
require('simple_html_dom.php');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.snowbird.com/mountain-report/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$content = curl_exec($ch);
curl_close($ch);
$html = new simple_html_dom();
$html->load($content);
$ret = $html->find('.horizSnowChartText');
$ret = serialize($ret);
$ret3 = new simple_html_dom();
$ret3->load($ret);
$es = $ret3->find('text');
$ret2 = $ret3->find('.total-inches');
print_r($ret2);
//print_r($es);
?>
【问题讨论】:
-
如果你已经找到了,一个简单的
echo就可以了 -
您只是想要总英寸数?
echo $ret3->find('.total-inches')->innertext; -
@Ohgodwhy 非常感谢你,我发现我的问题是没有使用 ->innertext,就像你在评论中显示的那样。
标签: php html curl simple-html-dom