php - 简单的 html dom - 结果与预期不同

标签 php web-scraping simple-html-dom

我尝试使用 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&regnr=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/

相关文章:

php - 在 PHP 中制作一个简单的模板引擎

php - 是否有可能在 PHP 中过度使用后期静态绑定(bind)?

javascript - Cheerio 查找嵌套表中的所有链接

javascript - 使用 jQuery 获取数据属性值列表

php - 使用 Simple HTML DOM Parser 按 ID 查找表

php - 简单的HTML DOM-(直接)子选择器

javascript - 使用 HTML DOM CSS (JS) 使我的弹出窗口淡入淡出

php - HTML mySQL 表单不起作用

php - 将 MySQL 查询中的多个列值存储到 PHP 数组中

python - soup.select() 中的 CSS 选择器返回 null