Get DIV content from external Website

前端 未结 4 1874
遥遥无期
遥遥无期 2020-11-29 22:53

I want to get a DIV from an external website with pure PHP.

External website: http://www.isitdownrightnow.com/youtube.com.html

Div text I want from isitdownr

4条回答
  •  一个人的身影
    2020-11-29 23:08

    This may be a little overkill, but you'll get the gist.

    preserveWhiteSpace = false;
    
    // Most HTML Developers are chimps and produce invalid markup...
    $doc->strictErrorChecking = false;
    $doc->recover = true;
    
    $doc->loadHTMLFile('http://www.isitdownrightnow.com/check.php?domain=youtube.com');
    
    $xpath = new DOMXPath($doc);
    
    $query = "//div[@class='statusup']";
    
    $entries = $xpath->query($query);
    var_dump($entries->item(0)->textContent);
    
    ?>
    

提交回复
热议问题