<?php
require './phpQuery.php';
//获取远程图片
function curl_file_get_contents($url,$from){
//初始化curl会话
$ch = curl_init();
//设置一个cURL传输选项。
curl_setopt($ch, CURLOPT_URL, $url); //目标
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
//curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
curl_setopt($ch, CURLOPT_REFERER,$from); //伪造来路
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
//载入文档
phpQuery::newDocumentFile('https://list.jd.com/list.html?cat=670,671,672');
$list = pq('li.gl-item');
$from = 'http://list.jd.com/list.html?cat=670,671,672';
for($i=0;$i<count($list);$i++){
$src = pq($list)->eq($i)->find('.p-img')->find('img')->attr('src');
if(!$src){
$src = pq($list)->eq($i)->find('.p-img')->find('img')->attr('data-lazy-img');
}
$src = str_replace('/n7/','/n1/',$src);
$result = curl_file_get_contents('http:'.$src,$from);
file_put_contents('./images/'.basename($src), $result);
}
?>
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!