Python - 字符串为多行时,转换为列表

Posted Rocinante

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python - 字符串为多行时,转换为列表相关的知识,希望对你有一定的参考价值。

例如一个IP代理池,这是个字符串,有多行
120.236.137.65:8060
193.112.208.216:8118
121.8.98.198:80
121.8.98.197:80
121.8.98.196:80
120.236.168.19:8060
123.207.6.117:80

import requests

resp = requests.get(GET_IP_API)

text = resp.text
print(text)

to_one_line = \' \'.join(text.split())
IP_LIST = a.split(\' \')

print(IP_LIST)

以上是关于Python - 字符串为多行时,转换为列表的主要内容,如果未能解决你的问题,请参考以下文章

将整数列表转换为 Python 中的预定义字符串列表

python用[]将int转换为list

python用[]将int转换为list

将字符串的python列表转换为字节数组

在 Python 中将字符串列表转换为整数(或双精度)

将 Python 列表转换为熊猫系列