여기 나는 cURL을 사용하여 웹 페이지에서 이미지를 가져 오는 기능이 있습니다. 대부분의 웹 사이트에서 작동하지만 일부 스크립트를 리디렉션하는 방법이 있습니다. 아래의 코드에서 예제로 사용 된 웹 사이트는 스크립트를 웹 페이지의 특정 페이지로 리디렉션합니다. 리디렉션을 사용하지 않거나 CURLOPT_MAXREDIRS로 제한하면 콘텐츠가 반환되지 않습니다 ... 여기서 내가 뭘 잘못하고 있니? cURL 이미지 스크레이퍼가 리디렉션됩니까?
function curl($url){
$headers[] = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
$headers[] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,
*/*;q=0.8";
$headers[] = "Accept-Language:en-us,en;q=0.5";
$headers[] = "Accept-Encoding:gzip,deflate";
$headers[] = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$headers[] = "Keep-Alive:115";
$headers[] = "Connection:keep-alive";
$headers[] = "Cache-Control:max-age=0";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
//curl_setopt($curl, CURLOPT_MAXREDIRS, 1);
$data = curl_exec($curl);
//$header = curl_getinfo($curl);
curl_close($curl);
return $data;
}
$data = curl("http://www.missselfridge.com/en/msuk/product/dress-shop-299048/view-all-299126/dark-floral-panel-midi-dress-3273361");
$images = array();
preg_match_all('~<img.*?src=["\']+(.*?)["\']+~', $data, $images);
...
//then for each image in images, is displayed in html.
내 브라우저
는 헤더 @Samuel Fullman응답 헤더는 HTTP-REFERRER가 자신의 페이지 중 하나 아니라고
CACHED_RESPONSE true
Cache-Control max-age=0, no-cache, no-store
Connection keep-alive
Content-Encoding gzip
Content-Language en-US
Content-Length 17121
Content-Type text/html; charset=UTF-8
Date Tue, 16 Sep 2014 16:27:42 GMT
Expires Tue, 16 Sep 2014 16:27:42 GMT
Pragma no-cache
Vary Accept-Encoding
요청 헤더
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control max-age=0
Connection keep-alive
Cookie ...
Host www.missselfridge.com
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
어쩌면 당신은 긁는 도구가 환영받지 못하고 어쨌든 길을 방해하려고해서는 안된다는 표시로 받아 들여야 할 것입니다. –
내 브라우저가하는 일과 다른 점은 무엇입니까? ... 난 그냥 스크립트를 통해 이미지를 수집하고 다시 사용자에게 표시하려고합니다. pintrest와 같이 웹에서 바로 이미지를 게시 할 수 있도록 스크래퍼를 사용하는 사이트가 많이 있습니다. – namenamesoseji
@MarcB, 나는 질문에 답하고 무엇인가 잘못되었다는 것을 구체적으로 나타내는 다른 정보가 부족할 때 최선을 다한 다음 OP 질문에 특별히 관련되지 않은 다른 요소를 정중하게 지적합니다. 그러나 OP의 경우 저작권 및 사용에 관한 사이트의 이용 약관을 확인해야합니다. –