以从小红书“复制链接”出来的一个地址为例,例如:http://xhslink.com/JDk1s 下面用PHP代码来实现提取图集,具体代码如下:
|', $content, $match)) {
$str = str_replace('undefined', '""', $match[1]);
$result = json_decode($str, true);
// 针对图集解析
if ($result['NoteView']['noteType'] == 'normal') {
$imageData = $result['NoteView']['content']['imageList'];
$images = [];
foreach($imageData as $info) {
$images[] = 'https:'.$info['url'];
}
print_r($images);
}
// 针对视频解析
if ($result['NoteView']['noteType'] == 'video') {
$videoUrl = $result['NoteView']['content']['video']['url'];
print_r($videoUrl);
}
}
function curlGet($url = '', $header = [], $userAgent = '') {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt ( $ch, CURLOPT_USERAGENT, $userAgent );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_MAXREDIRS, 5 );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 5 );
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
通过解析分享网页的方式,是可以得到高清的图片,也可以得到视频,但是都是有水印的。这个是目前很多人能做到的通用的做法
那么如何去掉这块的水印呢,实际上可以通过借助第三方API的方式来解决,具体的代码如下:
$appkey,
'url' => $url,
];
//得到请求的地址:https://api.vnil.cn/api/parse/deal?appkey=appkey&url=url
$apiUrl = 'https://api.vnil.cn/api/parse/deal?'.http_build_query($param);
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, $apiUrl );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt ( $ch, CURLOPT_MAXREDIRS, 5 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
$content = curl_exec( $ch );
curl_close ( $ch);
print_r($content);
通过上面的代码,就可以很直接的得到无水印的图片了