• 网站
  • 服务器状态
  • API 文档
  • 博客
Telegram Icon 社区
ZH
English
Português
Русский
中文 (中国)
Tiếng Việt
登录 试用仅需 €3.99
  • 网站
  • 服务器状态
  • API 文档
  • 博客
  • Telegram Icon 社区
  • Chinese
    English
    Português
    Русский
    中文 (中国)
    Tiếng Việt
登录 试用仅需 €3.99

通过API进行任务自动化

自动化您的任务需求与工作流程。

search icon

联系我们

如果您还有疑问,或希望直接从客服人员获得帮助,请提交请求。
我们会尽快回复您。

请填写下面的联系表格,我们会尽快回复您。

  • Multilogin X 入门指南
  • 如何开始使用 Multilogin X
  • 主要功能
    Agent 与启动器 功能 管理浏览器配置文件 Cookie 文件
  • 代理&掩蔽IP地址
  • 工作区 & 团队管理
  • 通过API进行任务自动化
    使用 Postman 进行低代码自动化 CLI自动化操作
  • 高级功能 & 自定义指纹
  • 迁移至Multilogin X
  • 常见问题的解决方案
    基本故障排除 常见问题 常见错误
  • 首页
  • breadcrumb separator bar
  • Multilogin X
  • breadcrumb separator bar
  • 通过API进行任务自动化
  • breadcrumb separator bar
  • 将外部代理列表转换为可供API直接调用的JSON 文件

将外部代理列表转换为可供API直接调用的JSON 文件

作者 Yelena V ( 更新于 September 11th, 2024 )

更新于 September 11th, 2024

在本文中,我们将向您展示如何将外部代理列表转换为可供API直接调用的JSON 文件。此方法允许您以JSON 格式保存所有代理数据,从而更轻松地与API端点集成。

开始之前

  1. 确保您已设置好 Python 环境并安装了以下依赖包:
    1. json
    2. re
  2. 将如下json_proxy_list保存到所需文件夹中

json_proxy_list

import json
import re

# Input the proxy list path here, if any.
file_path = "C:/Users/.../input_list.txt"

# Paste the proxy list here. Supported separators: comma, bar, space, newline
paste_list = """ 
host:port:username:password
"""

# Reading the proxies from the file path, if any
def read_proxies_from_file(file_path):
    try:
        with open(file_path, 'r') as file:
            return file.read()
    except Exception as e:
        print("Error reading file - please check your file PATH.")
        print(f'Exception found: {e}')
        return

# User input needed: proxy type (HTTP/SOCKS5)
def get_proxy_type():
    print("Enter the proxy type:")
    print("(1) HTTP")
    print("(2) HTTPS")
    print("(3) SOCKS5")
    choose_type = input()

    if choose_type == "1":
        proxy_type = "http"
    elif choose_type == "2":
        proxy_type = "https"
    elif choose_type == "3":
        proxy_type = "socks5"
    else:
        print("Invalid proxy type. Enter a valid option number.")
        return get_proxy_type()
    
    return proxy_type

# Detect line separator from block of credentials
def get_line_separator(proxy_list):
    # Detect the most common line separators
    separators = ['\n', ',', '/', ' ']
    separator_counts = {sep: proxy_list.count(sep) for sep in separators}
    sorted_separators = sorted(separator_counts, key=separator_counts.get, reverse=True)
    most_likely_separator = sorted_separators[0]

    # Handle double values such as '\n,' by checking combinations of common separators
    combined_separators = ['\n,', ',\n', '\n/', '/\n', '\n ', ' \n', ', ', ' ,', '/ ', ' /']
    for combo in combined_separators:
        if combo in proxy_list:
            return combo

    return most_likely_separator

# Main Function - Inputs user for preferred proxy list source
def main():
    # Select proxy list source
    print("Select the list source:")
    print("(1) from TEXT")
    print("(2) from PATH")
    choice = input()
    
    # Take action based on the script source
    if choice == '2':
        proxy_list_content = read_proxies_from_file(file_path)
        if proxy_list_content is None:
            return
    else:
        proxy_list_content = paste_list

    # Check if HTTP/SOCKS5
    proxy_type = get_proxy_type()

    # Split the proxy list based on detected separator
    proxy_lines = re.split(r'[\n, /]+', proxy_list_content.strip())

    # Add the proxy type to each line
    proxy_lines = [f"{proxy_type}:{line.strip()}" for line in proxy_lines if line.strip()]

    # Create JSON object that is similar to API output for easy future integration
    proxies_json = {
        "proxies": {
            "proxy": []
            }
        }

    # For each proxy line contained in the proxy list, take each proxy element to assign it.
    for line in proxy_lines:
        parts = line.split(':')
        if len(parts) != 5:
            print(f"Skipping invalid line: {line}. Please check your proxy credentials file.")
            continue
        proxy = {
            "type": parts[0],
            "host": parts[1],
            "port": parts[2],
            "username": parts[3],
            "password": parts[4]
        }
        proxies_json["proxies"]["proxy"].append(proxy)

    # Create the JSON.dumps, save it on proxies.json file.
    with open('proxies.json', 'w') as json_file:
        json.dump(proxies_json, json_file, indent=2)

    print("File proxies.json was written succesfully.")

if __name__ == "__main__":
    main()
 
 

运行脚本

  1. 打开终端并导航到包含脚本的文件夹
  2. 运行脚本json_proxy_list
  1. 选择您需要的代理详情列表来源:
    1. 在第 5 行粘贴.txt文件路径,或者
    2. 在第 8 行,粘贴代理详细信息字符串
  2. 选择代理类型:外部代理凭据通常不包含代理类型,因此这将正确地将类型附加到所有代理行
  3. 检查存储在同一文件夹中的proxies.json文件中的结果

这篇文章对您有帮助吗?

对本文提供反馈

在本文中

  • 开始之前
  • 运行脚本

Multilogin 社区

保持消息灵通,分享你的想法,并与他人互动!

Telegram Icon 加入我们的 Telegram 群组

阅读更多相关内容

Blog Post Img

10 Best Datacenter Proxies for Web Scraping (2025 Edition)

Apr 2, 2025 5 min read
Google SERP Img

What is a Google SERP Proxy and Why Should You Care?

Apr 1, 2025 6 min read
UK Proxy Img

What Are Dedicated UK Proxies? Everything You Need to Know

Apr 1, 2025 6 min read
Related Article Title Icon

相关文章

  • Multilogin X自动化常见问题解答
  • Selenium浏览器自动化示例
  • Puppeteer自动化示例
  • 检索获取配置文件、文件夹和工作台ID

平台

  • 防侦测浏览器
  • 移动防关联浏览器
  • 无头浏览器
  • 住宅代理服务
  • 多账号管理
  • 网页自动化

相关资源

  • 知识库
  • API 文档
  • 术语表
  • 博客
  • Multilogin 6 下载
  • 服务器状态
  • 版本说明

网络自动化

  • 票务倒卖

网络抓取

  • Facebook账户抓取工具
  • 亚马逊抓取工具
  • OnlyFans抓取工具
  • 推特抓取
  • 领英抓取
  • 谷歌抓取工具

空投

  • 扩大你的空投耕作
  • Solana空投
  • 加密货币空投

比较

  • Multilogin与GoLogin对比
  • Multilogin与AdsPower对比
  • Multilogin与Dolphin Anty 对比
  • Multilogin与Incogniton 对比
  • Multilogin与Octo Browser 对比

联系我们

  • 24/7支持服务
    [email protected]
  • 联系销售
  • 联盟计划
  • 开放职位

© 2025 Multilogin。保留所有权利。

  • 隐私政策
  • 服务条款
  • Cookie政策
Multilogin abstract watermark
  • 平台

    • 防侦测浏览器
    • 移动防关联浏览器
    • 无头浏览器
    • 住宅代理服务
    • 多账号管理
    • 网页自动化
  • 相关资源

    • 知识库
    • API 文档
    • 术语表
    • 博客
    • Multilogin 6 下载
    • 服务器状态
    • 版本说明
  • 空投

    • 扩大你的空投耕作
    • Solana空投
    • 加密货币空投
  • 比较

    • Multilogin与GoLogin对比
    • Multilogin与AdsPower对比
    • Multilogin与Dolphin Anty 对比
    • Multilogin与Incogniton 对比
    • Multilogin与Octo Browser 对比
  • 网络自动化

    • 票务倒卖
  • 网络抓取

    • Facebook账户抓取工具
    • 亚马逊抓取工具
    • OnlyFans抓取工具
    • 推特抓取
    • 领英抓取
    • 谷歌抓取工具
  • 联系我们

    • 7×24 小时支持:[email protected]
    • 联系销售
    • 联盟计划
    • 开放职位
Multilogin abstract watermark
  • 隐私政策
  • 服务条款
  • Cookie政策

© 2025 M© 2024 Multilogin。保留所有权利。

Expand