我正在尝试使用Xpath学习网页抓取。下面的代码有效,但输出包含不正确的字符,我无法设法做到这一点。
示例:
PHP代码:
<?php
// Tried with these parameters but they doesn't make any difference
$html = new DOMDocument('1.0', 'UTF-8');
$html->loadHtmlFile('http://thesite.com/thedoc.html);
$xpath = new DOMXPath($html);
$nodelist = $xpath->query("//table");
foreach ($nodelist as $n) {
echo $n->nodeValue."\n";
}
?>
我该怎么做才能解决这个问题?