<分区>
Possible Duplicate:
read XML tag id from php
使用 PHP 从特定的 div id 获取数据的方法是什么。我想要做的是从一个名为 <div id="content">
的 div id 中获取数据,因此来自该 div id 的所有数据都将在一个变量中获取。
我可以使用我的脚本获取所有内容,但无法过滤它以从特定的 div 标签获取数据。
这是我的脚本我正在使用获取任何内容:
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl("http://www.example.com");
//parsing all content:
$doc = new DOMDocument();
@$doc->loadHTML($html);
echo "$html";
有什么想法吗?