2

シンプルな HTML DOM ライブラリをインクルードしているときに、次の警告が表示されます。

警告: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo に失敗しました: そのようなホストは不明です。C:\xampp\htdocs\simple_html_dom.php の 70 行目

警告: file_get_contents(http://www.google.com/) [function.file-get-contents]: ストリームを開けませんでした: php_network_getaddresses: getaddrinfo に失敗しました: そのようなホストは不明です。C:\xampp\htdocs\simple_html_dom.php の 70 行目

simple_html_dom.php ファイル ( http://sourceforge.net/projects/simplehtmldom/files/latest/downloadからダウンロード) の 70 行目は

  $contents = file_get_contents($url, $use_include_path, $context, $offset);

また、1エラー:

致命的なエラー: 15 行目の C:\xampp\htdocs\domdoc2.php の非オブジェクトに対するメンバー関数 find() の呼び出し

コードの 15 行目 (以下) は

foreach($html->find('img') as $element) 

以下のコードで参照していた Web ページは google.com コードは次のとおりです。

     <?php

include('simple_html_dom.php');
$html = new simple_html_dom();  
$html = file_get_html('http://www.google.com/');
// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';
?>

私は何を間違っていますか??

4

2 に答える 2

2

これは、ホストが DNS を解決できなかったためです。これは、simplehtmldom が curl の代わりに file_get_contents を使用している場合に発生します。PHP Simple HTML DOM Parser は優れた HTML 解析 PHP クラスですが、cURL の代わりに file_get_contents (ほとんどすべての構成で無効になっています) を使用するため遅いです (4-5 倍速く、多くのオプションがあり、ほとんどすべてのサーバーがそれを持っています)。 .

file_get_contents のみが置き換えられるため、以前のバージョンを安全に上書きでき、すべてが以前と同じように動作し、高速になります

ソースコードへのリンク: http://webarto.com/static/download/simple_html_dom.rar

//output should be

/intl/en_ALL/images/srpr/logo1w.png
http://www.google.com/webhp?hl=en&tab=ww
http://www.google.com/imghp?hl=en&tab=wi
http://maps.google.com/maps?hl=en&tab=wl
https://play.google.com/?hl=en&tab=w8
http://www.youtube.com/?tab=w1
http://news.google.com/nwshp?hl=en&tab=wn
https://mail.google.com/mail/?tab=wm
https://docs.google.com/?tab=wo
http://www.google.com/intl/en/options/
https://www.google.com/calendar?tab=wc
http://translate.google.com/?hl=en&tab=wT
http://www.google.com/mobile/?tab=wD
http://books.google.com/bkshp?hl=en&tab=wp
https://www.google.com/offers/home?utm_source=xsell&utm_medium=products&utm_campaign=sandbar&tab=wG#!details
https://wallet.google.com/manage/?tab=wa
http://www.google.com/shopping?hl=en&tab=wf
http://www.blogger.com/?tab=wj
http://www.google.com/reader/?hl=en&tab=wy
http://www.google.com/finance?tab=we
http://picasaweb.google.com/home?hl=en&tab=wq
http://video.google.com/?hl=en&tab=wv
http://www.google.com/intl/en/options/
https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com/
http://www.google.com/preferences?hl=en
/preferences?hl=en
/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg
http://www.google.com/history/optout?hl=en
/advanced_search?hl=en
/language_tools?hl=en
/intl/en/ads/
/services/
https://plus.google.com/116899029375914044550
/intl/en/about.html
/intl/en/policies/

ただし、PHP での HTML 解析にまったく慣れていない場合は、以下をお読みください: PHPで HTML/XML を解析および処理するにはどうすればよいですか?

于 2012-06-22T07:27:28.793 に答える
1

これは、とはまったく関係ありませんsimple_html_dom。サーバーにインターネットアクセスがなく、解決に失敗しますgoogle.com。DNS設定とおそらくファイアウォールを確認してください。

于 2012-06-22T07:22:32.500 に答える