【发布时间】:2014-06-08 02:38:45
【问题描述】:
我正在尝试使用 PHP 抓取网站页面,然后自动抓取图像。
我尝试了以下方法:
<?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 中抓取该页面时失败了。
有什么我可以尝试的吗?
【问题讨论】:
标签: php file-get-contents