使用 PHP 从 HTML 的 <i> 标签中提取信息

Extracting information from <i> tag from HTML using PHP

提问人:Justinas 提问时间:7/22/2021 最后编辑:ADysonJustinas 更新时间:7/22/2021 访问量:26

问:

我有一些代码并收到 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'));

?>

谢谢。

php html 解析

评论

0赞 ADyson 7/22/2021
您在这里没有使用 cURL(您似乎使用了 file_get_contents) - 我已经为您编辑了它。
0赞 ADyson 7/22/2021
无论如何,500 内部服务器错误是一条通用错误消息,通知您在处理请求时服务器崩溃。除此之外,它(故意)毫无意义,对调试几乎没有用处。您需要检查服务器上的错误日志,以尝试查找基础异常消息。一旦你掌握了这一点,你就有机会发现问题所在。
0赞 ADyson 7/22/2021
或者,您可以暂时打开错误报告(但如果是实时服务器,请确保不要将其保持打开状态):stackoverflow.com/questions/845021/...

答: 暂无答案