使用PHP我試圖抓取一個網頁,然後自動抓取圖像。PHP 500內部服務器錯誤file_get_contents
我已經試過如下:
<?php
$url = "http://www.domain.co.uk/news/local-news";
$str = file_get_contents($url);
?>
和
<?php
$opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('http://www.domain.co.uk/news/local-news',false,$context);
?>
也
<?php
include('simple_html_dom.php');
$html = file_get_html('http://www.domain.co.uk/news/local-news');
$result = $html->find('section article img', 0)->outertext;
?>
但這些都返回與Internal Server Error
。我可以在瀏覽器中完美地查看網站,但是當我嘗試在PHP中抓取頁面時,它會失敗。
有什麼我可以嘗試嗎?
[啓用錯誤報告](http://blog.flowl.info/2013/enable-display-php-errors/) – DanFromGermany
[PHP文件\ _get \ _contents 500內部服務器錯誤](http:/ /stackoverflow.com/questions/10524748/php-file-get-contents-500-internal-server-error) – majidarif