You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python解码代理网站document.write输出的加密代理端口

实现方案

核心原理

原网站提前在全局作用域定义了Zero、Five这类单词拼接的变量,每个变量值对应单词拼写的阿拉伯数字。你提取到的表达式本质是「两次按位异或运算的结果转字符串拼接」,我们只需要把单词替换成对应数字,再计算异或即可得到端口。

实现代码

import re

def parse_proxy_port(exp_str):
    # 英文数字单词到阿拉伯数字的映射表
    word_to_num = {
        'Zero': '0',
        'One': '1',
        'Two': '2',
        'Three': '3',
        'Four': '4',
        'Five': '5',
        'Six': '6',
        'Seven': '7',
        'Eight': '8',
        'Nine': '9'
    }
    # 提取所有括号内的异或表达式
    xor_exp_list = re.findall(r'\((.*?)\)', exp_str)
    port_part_list = []
    for exp in xor_exp_list:
        # 替换表达式中所有英文数字单词为阿拉伯数字
        for word, num in word_to_num.items():
            exp = exp.replace(word, num)
        # 拆分异或左右操作数,计算结果
        left_num, right_num = exp.split('^')
        xor_result = int(left_num) ^ int(right_num)
        port_part_list.append(str(xor_result))
    # 拼接成最终端口格式
    return ':' + ''.join(port_part_list)

调用示例

# 你通过BeautifulSoup提取到的表达式字符串
raw_exp = '(ZeroFiveSevenFive^FiveSevenOne)+(Eight5EightFour^Seven3Zero)'
port = parse_proxy_port(raw_exp)
print(port) # 输出对应端口格式,示例场景下为:80

报错原因说明

你在其他网站控制台执行报错是因为只有原代理网站的页面提前定义了ZeroFiveSevenFive这类全局变量,第三方网站没有对应变量定义,自然会抛出未定义的引用错误。

内容的提问来源于stack exchange,提问作者George Pamfilis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 20:45:04