【发布时间】:2013-10-09 22:11:41
【问题描述】:
我尝试使用 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
当用我的浏览器访问上面的 URL 时,我得到了我期望的内容。
当使用 $resultcontent 检索内容时,我得到了不同的结果,它在挪威语中显示为“无效输入”。
任何想法为什么?
【问题讨论】:
-
哦,天哪,这很难,我尝试了很多方法来下载页面,但仍然遇到同样的错误......奇怪的是,当你用预期的链接替换
$result时,它显示正确的输出!!!所以它可能在提取的链接中有一些隐藏的字符,我个人找不到任何 :-/ 真是个难题 xD -
这是一个艰难的过程,但通过下面的答案解决了!感谢您提供帮助!
标签: php web-scraping simple-html-dom