如何解决修正错误的Python阵列格式
由于某种原因,我无法以正确的格式打印整个数组或循环遍历。
数组中的每个条目都应该是一个单独的URL。
import requests
import json
response = requests.get('https://newtrackon.com/api/live')
#print(response.text)
my_input = []
my_input.append(response.text)
#print(my_input)
x = my_input[0]
print(x)
#for a in x:
# print(a)
解决方法
您需要将URL中的字符串拆分为列表的元素。
import requests
import json
response = requests.get('https://newtrackon.com/api/live')
my_input = response.text.split("\n")
print(len(my_input))
# Remove the blank rows
my_input = list(filter(None,my_input))
print(len(my_input))
,
替换
my_input = []
my_input.append(response.text)
使用
my_input = response.text.split("\n\n")
response.text
将所有网址作为单个字符串返回
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。