python - 从 .txt 将代理添加到 python 中的字典
问题描述
目标是让我的文本文件每行包含 1 个代理,ip:port
在我的 python 脚本中格式化为字典。到目前为止,我对 python 很感兴趣,但这个问题让我想把头发拉出来——我读过很多问题,但似乎没有一个是我想要的。
这是我目前正在使用的:
proxies = {}
def addproxies(a,b,proxies):
proxies[ip].append(a),
proxies[port].append(b)
return proxies
def main():
with open('proxies.txt', 'r') as this_file:
for line in this_file:
addproxies((this_file.split(':'),[0]),(this_file.split(':')[1]),proxies)
非常感谢任何帮助
解决方案
试试这个:
def main():
proxies = {}
with open('proxies.txt', 'r') as this_file:
for line in this_file:
ip, port = line.strip().split(":")
proxies[ip] = port
推荐阅读
- php - 如何编辑我的 WooCommerce 迷你购物车价格和链接文本
- jquery - 在 Rails 5 中使用 jquery 自动完成多个字段
- android - 每当进入特定活动屏幕时,应用程序会因 Pending Intent 而崩溃
- java - 无法打开玛丽模拟器
- mysql - mysql slave db错误连接到master
- python - Python/Pandas 通过一个限制获得所有可能的组合
- linux - 在子目录中获取最新的文件(同名)
- c++ - C++ 运算符优先级查询
- inno-setup - 在 Inno Setup 的自定义页面上显示控件背后的背景
- c# - 当我想使用我的搜索功能时,数据未从 UWP 中的 SQL Server 数据库中显示,带有 gridview 和错误