gpt4 book ai didi

PhP curl simple_dom_document 请求从 snowbird.com 获取雪数据

转载 作者:行者123 更新时间:2023-11-28 01:21:44 24 4
gpt4 key购买 nike

我使用 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);
?>

这是输出的图片。您可以看到它跳过了实际的雪数据并直接转到英寸标记“。 outputcode

最佳答案

请注意,您获得的 html 标记有多个 .total-inches 实例(具有此类的多个节点)。如果你想明确地得到一个,你可以直接使用 ->find() 的第二个参数指向它。

例子:

$ret2 = $html->find('.total-inches', 3);
// ^

如果你想把它们全部检查出来,一个简单的foreach就足够了:

foreach($html->find('.current-conditions .snowfall-total .total-inches') as $in) {
echo $in , "\n";
}

关于PhP curl simple_dom_document 请求从 snowbird.com 获取雪数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33685292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com