【发布时间】:2021-06-06 18:30:29
【问题描述】:
我正在尝试使我的结果类似于:
proxies_dict = {
'http':'http://178.141.249.246:8081',
'http':'http://103.12.198.54:8080',
'http':'http://23.97.173.57:80',
}
我试过了
proxies_dict = {}
with open('proxies.txt', 'r') as proxy_file:
for proxy in proxy_file:
proxies_dict['http'] = 'http://' + proxy.rstrip()
print(proxies_dict)
但这只会添加代理的最后一行,而不是全部。如何让它在我的 .txt 文件中添加每个代理?
【问题讨论】:
-
字典中的键必须是唯一的。您应该将链接设置为它们的列表,例如
{‘http’: [link1,…,linkn]} -
我该如何解决? @David 我逻辑很烂
-
除了
http,您还使用其他密钥吗?
标签: arrays python-3.x dictionary python-requests proxies