开发者

Python Flask框架实现小红书图片无水印解析下载

目录
  • 摘要
  • 代码
  • 演示
  • php版

摘要

小红书的图片如果是长按保存是有水印的,如何获得无水印的图片?当然是通过网页解析!

代码

from flask import Flask, request, jsonwww.devze.comify
import requests
import re
app = Flask(__name__)
@app.route('/')
def index():
    url = request.args.get('url')
    if url:
        result = get_image_urls(url)
        return jsonify(result)
    else:
        return jsonify({'error': 'Missing URL parameter'})
def get_html(url):
    headers = {
        "authority": "www.xiaohongshu.compython",
        "cache-control": "max-age=0",
        "sec-ch-ua": '"Chromium";v="21", " Not;A Brand";v="99"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
        "upgrade-insecure-requests": "1",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
        "accept": "text/html,application/Xhtml+XML,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "sec-fetch-site": "same-origin",
        "sec-fetch-mode": "navigate",
        "sec-fetch-user": "?1",
        "sec-fetch-dest": "document",
        "accept-language": "zh-CN,zh;q=0.9",
    }
    response = requests.get(url, headers=headers)
    return response.text
def json_content(html):
    rule = r"<script>window\.__INITIAL_STATE__=(.*?)</script>"
    js = re.search(rule, html, re.I)
    if js:
        content = js.group(1)
        return content
    else:
        return None
def get_image_urls(url):
    html = get_html(url)
    js = json_content(html)
    js = js.replace(r"\u002F", r"/")
    all_urls = re.findall(r'url":"(http://[^\":\{\}\[\]]*?wm_1)"', js)
    return {'image_urls': all_urls}
if __name__ == "__main__":
    app.run(debug=True)

使用 python的Flask框架实现一个简单的HTTP服务器,然后通过?url=小红书链接,就可以解析出小红书无水印的图片地址。

演示

Python Flask框架实现小红书图片无水印解析下载

Python Flask框架实现小红书图片无水印解析下载

http://127.0.0.1:5000/?url=http://xhslink.com/wZh4pw

PHP版

<?php
 
    function get_html($url) {
        $headers = array(
            "authority" => "www.xiaohongshu.com",
            "cache-control" => "max-age=0",
            "sec-ch-ua" => '"Chromium";v="21", " Not;A Brand";v="99"',
            "sec-ch-ua-mobile" => "?0",
            "sec-ch-ua-platform" => '"Windows"',
            "upgrade-insecure-requests" => "1",
            "user-agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safarihttp://www.devze.com/537.36",
            "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "sec-fetch-site" => "same-origin",
            "sec-fetch-mode" => "navigate",
            "sec-fetch-user" => "?1",
            "sec-fetch-dest" => "document",
            "accept-language" => "zh-CN,zh;q=0.9",
        );
     
        $options = array(
      编程客栈      'http' => array(
                'header' => implode("\r\n", array_map(
                    function ($v, $k) {
                        return $k . ':' . $v;
                    },
                    $headers,

以上就是Python Flask框架实现小红书图片无水印解析下载的详细内容,更多关于Phttp://www.devze.comython Flask图片无水印的资料请关注编程客栈(www.devze.com)其它相关文章!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜