php – 从外部网站获取DIV内容

我想从纯 PHP的外部网站获得DIV.

外部网站:http://www.isitdownrightnow.com/youtube.com.html

我希望来自isitdownrightNow(statusup div)的Div文本:< div class =“statusup”>该网站可能只适合您…< / div>

我已经尝试过使用DOMDocument和str_get_html的file_get_contents,但我无法让它工作.

例如这个

$page = file_get_contents('http://css-tricks.com/forums/topic/jquery-selector-div-variable/');
    $doc = new DOMDocument();
    $doc->loadHTML($page);
    $divs = $doc->getElementsByTagName('div');
    foreach($divs as $div) {
        // Loop through the DIVs looking for one withan id of "content"
        // Then echo out its contents (pardon the pun)
        if ($div->getAttribute('class') === 'bbp-template-notice') {
             echo $div->nodeValue;
        }
    }

它只会在控制台中显示错误

Failed to load resource: the server responded with a status of 500
(Internal Server Error)

解决方法

这就是我经常使用的:

$url = 'https://somedomain.com/somesite/';
$content = file_get_contents($url);
$first_step = explode( '<div id="thediv">',$content );
$second_step = explode("</div>",$first_step[1] );

echo $second_step[0];

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...