2

次のように、simple_html_dom を使用して Web ページから情報を取得しようとしています。

<?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 を提供します

ブラウザで上記の URL にアクセスすると、期待どおりのコンテンツが表示されます。

$resultcontent を使用してコンテンツを取得すると、別の結果が得られます。ノルウェー語で「無効な入力」と表示されます。

理由はありますか?

4

2 に答える 2

1
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;

       }

これでうまくいくはずです。

于 2013-10-11T10:30:43.927 に答える