我必须提取一些具有css类的特定div的内容,例如“whole-content”。但重要的是用HTML标签获取内容。
$ch = curl_init("http://hihi2.com/2014/04/14/p215331.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);
$dom = new DOMDocument('1.0', "UTF-8");
@$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$cl);
$xpath = new DomXPath($dom);
$title = $xpath->query("//div[@class='float_right']/span/a");
echo "<pre>";
foreach ($title as $key=>$value){
$titlear[$key] = ($value->nodeValue);
}
它将全部内容作为文本提供给我,我需要用它的标签包围的文本。