From b408a1e1b2f586cb869222bdf650a42de1a8caab Mon Sep 17 00:00:00 2001 From: iamzhaohaibo <941604465@qq.com> Date: Sat, 3 Jan 2026 08:49:49 +0000 Subject: [PATCH] =?UTF-8?q?add=20Web/ProxyImagesDemo/demo.py.=20=E5=BD=93?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=88=E7=8A=B6=E6=80=81=E7=A0=81403=E6=97=B6?= =?UTF-8?q?=EF=BC=89=E5=8F=AF=E4=BB=A5=E5=8F=82=E8=80=83=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=E5=9B=BE=E7=89=87=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: iamzhaohaibo <941604465@qq.com> --- Web/ProxyImagesDemo/demo.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Web/ProxyImagesDemo/demo.py diff --git a/Web/ProxyImagesDemo/demo.py b/Web/ProxyImagesDemo/demo.py new file mode 100644 index 0000000..5396777 --- /dev/null +++ b/Web/ProxyImagesDemo/demo.py @@ -0,0 +1,31 @@ +@app.route('/proxy-image/') +def proxy_image(image_url): + """ + 图片代理路由,用于绕过跨域限制 + """ + try: + # 重新构建完整URL(如果需要的话) + if not image_url.startswith(('http://', 'https://')): + full_url = 'https://' + image_url.lstrip('/') + else: + full_url = image_url + + # 添加请求头来模拟浏览器请求 + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', + 'Referer': 'https://movie.douban.com/', + 'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8' + } + + response = requests.get(full_url, headers=headers, timeout=10) + + if response.status_code == 200: + # 返回图片内容 + image_data = BytesIO(response.content) + content_type = response.headers.get('Content-Type', 'image/jpeg') + return send_file(image_data, mimetype=content_type) + else: + abort(404) + except Exception as e: + print(f"Error fetching image: {e}") + abort(404) \ No newline at end of file