【发布时间】:2014-03-29 17:14:48
【问题描述】:
我正在尝试使用以下代码从网站上抓取一些产品详细信息:
$list_url = "http://www.topshop.com/en/tsuk/category/sale-offers-436/sale-799";
$html = file_get_contents($list_url);
echo $html;
但是,我收到了这个错误:
警告: file_get_contents(http://www.topshop.com/en/tsuk/category/sale-offers-436/sale-799) [function.file-get-contents]:无法打开流:HTTP 请求 失败的! HTTP/1.0 403 禁止在 /homepages/19/d361310357/htdocs/shopaholic/rss/topshop_f_uk.php 上 第 123 行
我认为这是网站为防止抓取而设置的某种屏蔽。有没有办法解决这个问题 - 也许使用 cURL 并设置用户代理?
如果没有,是否有其他方法可以获取商品名称和价格等基本产品数据?
编辑
我的代码上下文是我最终仍然希望能够实现以下目标:
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
【问题讨论】:
标签: php web-scraping http-status-code-403