我想用纯PHP从外部网站获取一个DIV。
外部网站:http://www.isitdownrightnow.com/youtube.com.html
我想要的来自isitdownrightnow(statusup div)的div文本是:<div class="statusup">The website is probably down just for you...</div>
我已经尝试过使用file_get_contents
与DOMDocument
和str_get_html
,但是我无法让它正常工作。
例如这个:
$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;
}
}
它只会在控制台显示一个错误:
未能加载资源:服务器响应状态为500(内部服务器错误)