from flask import Flask, request, Response
import requests
import re
app = Flask(__name__)
# 首页
@app.route('/')
def home():
return '''
🌐 国外网站代理访问
🌐 Github / 国外网站加速代理
'''
# 统一替换 html 内资源链接与表单 action
def replace_all_resources(html, target_url):
def replace_match(match):
attr, url = match.group(1), match.group(2)
if url.startswith('http'):
proxied_url = f"/proxy?url={url}"
elif url.startswith('//'):
proxied_url = f"/proxy?url=https:{url}"
elif url.startswith('/'):
base = re.match(r'(https?://[^/]+)', target_url).group(1)
proxied_url = f"/proxy?url={base}{url}"
else:
base = target_url.rsplit('/', 1)[0]
proxied_url = f"/proxy?url={base}/{url}"
return f'{attr}="{proxied_url}"'
# 替换 src / href / action
html = re.sub(r'(src|href|action)=["\'](.*?)["\']', replace_match, html, flags=re.IGNORECASE)
# 给所有表单加隐藏 input 保留 url 参数
html = re.sub(
r'(