我尝试使用下面的代码刮从网站的一些产品细节:403错误
$list_url = "http://www.topshop.com/en/tsuk/category/sale-offers-436/sale-799";
$html = file_get_contents($list_url);
echo $html;
不过,我得到这个错误:
Warning: file_get_contents(http://www.topshop.com/en/tsuk/category/sale-offers-436/sale-799) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /homepages/19/d361310357/htdocs/shopaholic/rss/topshop_f_uk.php on line 123
我认为这是网站阻止拼写的一种方式。有没有办法解决这个问题 - 也许使用cURL并设置用户代理?
如果没有,是否有另一种获取基本产品数据的方法,如项目名称和价格?
编辑
我的代码的上下文是我最终还是希望能够实现如下:
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);