提问人:Justinas 提问时间:7/22/2021 最后编辑:ADysonJustinas 更新时间:7/22/2021 访问量:26
使用 PHP 从 HTML 的 <i> 标签中提取信息
Extracting information from <i> tag from HTML using PHP
问:
我有一些代码并收到 HTTP 500 错误。有点困惑。我需要从天气投射的网络中提取天气数字信息并添加到网站中。
代码如下:
orai_class.php
<?php
Class orai{
var $url;
function generate_orai($url){
$html = file_get_contents($url);
$classname = 'wi wi-1';
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$results = $xpath->query("//*[@class='" . $classname . "']");
$i=0;
foreach($results as $node)
{
if ($results->length > 0) {
$array[] = $results->item($i)->nodeValue;
}
$i++;
}
return $array;
}
}
?>
索引:.php
<?php
include("orai.class.php");
$orai = new orai();
print_r($orai->generate_orai('https://orai.15min.lt/prognoze/vilnius'));
?>
谢谢。
答: 暂无答案
评论