如何使用 Python 导出全局IP信息
使用这个 Python 脚本,将 Multilogin 浏览器配置文件中保存的全局IP设置导出为 JSON 文件。
手动添加配置文件 ID、从 JSON 文件加载,或使用 Profile Search → 脚本将 ID 发送给 Profile Metas → 导出的全局IP信息保存为 proxy_credentials.json。
需要将多个浏览器配置文件的全局IP配置保存为结构化文件时,可以使用此方法。
开始前的准备
- 确认已安装 Python,然后安装脚本所需的外部包:
python -m pip install requestsjson模块已包含在 Python 中。 - 将脚本
proxies_to_json.py保存到所需文件夹
proxies_to_json.py
import json
import requests
# TODO: Insert your automation token in the variable below
API_TOKEN = ""
# Insert Your FolderID here
FOLDERID = "91f042e6-xxx-4e1f-adee-5eed6bb47d60"
# Insert your profile_ids.json filepath here
LIST_PATH = "C:/.../files/pid_list.json"
# Paste your string values manually:
LIST_MANUAL = [
"95f6d02c-xxxx-47c4-b1d4-369801f2a37c",
"48da90d8-xxxx-40a2-8ccb-2d9e7e3eaebb",
"e2f9d96a-xxxx-4439-ae74-10beda6bf109",
"fffca377-xxxx-495e-a408-3a98716e14ea",
"f3559ca3-xxxx-479c-8a8a-c4b831e8f78b",
"1c1e09dc-xxxx-4495-979b-7cb805a3a8a1",
"a66ba910-xxxx-48ac-a6d1-615f996b3a1d",
"f17140f4-xxxx-47c5-96d5-1b9fd184203b",
"0a505d93-xxxx-4ba9-bd25-d37bf8bb168d",
]
# API-Related Objects
LOCALHOST = "http://127.0.0.1"
LAUNCHERV1 = "https://launcher.mlx.yt:45001/api/v1"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}
# Search Profiles called "TempName": recently created by the Bulk Create function.
def profile_search():
url = "https://api.multilogin.com/profile/search"
body = {
"is_removed": False, # Do you wish to search for removed profiles? True/False
"limit": 100, # How many profile results do you wish to get?
"offset": 0, # Check MLX Documenter page for a full parameter breakdown
"search_text": "",
"storage_type": "all",
"order_by": "created_at",
"sort": "asc",
}
response = requests.request("POST", url, headers=HEADERS, json=body)
resp_json = json.loads(response.content)
return resp_json
# Obtain a list of ProfileIDs retrieved by the Profile Search endpoint
def get_profile_ids():
profile_list = profile_search()
if profile_list["data"]["total_count"] == 0:
print("No more profiles found: error in response or end of task.")
return []
else:
if (
profile_list
and "data" in profile_list
and "profiles" in profile_list["data"]
):
profile_ids = [
profile["id"] for profile in profile_list["data"]["profiles"]
]
return profile_ids
else:
print("Error - Please check Get Profile IDs function.")
# Use Profile Metas endpoint to get the Proxy information registrered.
def search_proxy_metas(option_call):
url = "https://api.multilogin.com/profile/metas"
if option_call == "1":
payload = json.dumps({"ids": LIST_MANUAL})
elif option_call == "2":
payload = json.dumps({"ids": get_profile_ids()})
elif option_call == "3":
with open(LIST_PATH, "r") as file:
proxies = json.load(file)
payload = json.dumps({"ids": proxies})
else:
print("Invalid option. Restart.")
return
response = requests.request("POST", url, headers=HEADERS, data=payload)
response_object = response.text
extracted_data = json.loads(
response_object
) # Full Profile Metas object (not only proxies)
query_result = []
for profile in extracted_data["data"]["profiles"]:
proxy_metas = profile["parameters"]["proxy"]
query_result.append(proxy_metas)
proxy_json = json.dumps(query_result, indent=4)
print(proxy_json)
# Write the JSON with results
with open("proxy_credentials.json", "w") as json_file:
json_file.write(proxy_json)
print(
f"Total of {len(query_result)} proxies were saved on proxy_credentials.json \n"
)
# Main function
def main():
HEADERS.update({"Authorization": f"Bearer {API_TOKEN}"})
option_call = input(
"\n\n Select method to find proxy list: \n (1) from PATH \n (2) from Profile Search \n (3) Manual List (line 14) \n Write Selection: \n "
)
search_proxy_metas(option_call)
if __name__ == "__main__":
main()选择要导出的浏览器配置文件
脚本可通过三种方式获取配置文件 ID:
- 手动列表:将指定配置文件 ID 直接添加到
LIST_MANUAL - Profile Search:从当前工作区检索配置文件
- JSON 文件:从
LIST_PATH指定的文件加载配置文件 ID
运行脚本
- 打开终端,进入脚本所在文件夹
- 运行脚本
proxies_to_json.py - 按提示选择所需的输入方式
可以通过路径、文本或搜索输入配置文件 ID 列表,也可以使用 Profile Search 端点的结果。使用 Profile Search 选项时,请相应调整函数参数。
- 查看同一文件夹中
proxy_credentials.json文件的结果
预期结果:脚本在同一文件夹中创建 proxy_credentials.json,并为每个已保存全局IP信息的所选浏览器配置文件写入一个全局IP配置对象。
请确认用于此脚本的配置文件中包含全局IP信息。第二种输入方式尤其需要注意,因为 Profile Search 端点默认检索工作区中的前 100 个配置文件。