【发布时间】:2012-07-25 17:07:04
【问题描述】:
我有一个合作伙伴创建了一些内容供我抓取。
我可以使用我的浏览器访问该页面,但是当我尝试使用file_get_contents 时,我得到了一个403 forbidden。
我尝试过使用stream_context_create,但这无济于事 - 可能是因为我不知道应该在那里输入什么。
1) 我有什么方法可以抓取数据吗?
2) 如果没有,并且不允许合作伙伴配置服务器允许我访问,我该怎么办?
我尝试使用的代码:
$opts = array(
'http'=>array(
'user_agent' => 'My company name',
'method'=>"GET",
'header'=> implode("\r\n", array(
'Content-type: text/plain;'
))
)
);
$context = stream_context_create($opts);
//Get header content
$_header = file_get_contents($partner_url,false, $context);
【问题讨论】:
标签: php html http-headers screen-scraping