我尝试使用 simple_html_dom 从网页检索信息,如下所示:
<?PHP
include_once('dom/simple_html_dom.php');
$urlpart="http://w2.brreg.no/motorvogn/";
$url = "http://w2.brreg.no/motorvogn/heftelser_motorvogn.jsp?regnr=BR15597";
$html = file_get_html($url);
foreach($html->find('a') as $element)
if(preg_match('*dagb*',$element)) {
$result=$urlpart.$element->href;
$resultcontent=file_get_contents($result);
echo $resultcontent;
}
?>
$result 变量首先给我这个 URL: http://w2.brreg.no/motorvogn/dagbokutskrift.jsp?dgbnr=2011365320&embnr=0®nr=BR15597
当使用浏览器访问上述网址时,我得到了我期望的内容。
当使用 $resultcontent 检索内容时,我得到了不同的结果,其中显示挪威语“无效输入”。
有什么想法吗?
最佳答案
foreach($html->find('a') as $element)
if(preg_match('*dagb*',$element)) {
$result=$urlpart.$element->href;
$resultcontent=file_get_contents(html_entity_decode($result));
echo $resultcontent;
}
这应该可以解决问题。
关于php - 简单的 html dom - 结果与预期不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19283729/