简体   繁体   English

如何将字符串的某些部分放入列表

[英]How to put certain parts of a string into a list

So i have the code 所以我有代码

op = urlopen('http://example.com/download_music/' + mus + '-1.html')

ops = op.read()
af = file('mus.txt', 'w')
asv = file('mu.txt', 'w')
af.write(str(ops))
if 'charset="utf-8">var playlist' in ops:
    print 'yes'
    cal = ops.split('charset="utf-8">var playlist',1)
    del cal[0]
    asv.write(str(cal))
    cv = str(cal)
    cals = cv.split('},];</script><div',1)
    del cals[1]


cals = str(cals)
v = cals.replace('{', '''

''')


vn = v.replace('[','')
vnm = vn.replace(']','')

print vnm

Then i have the author,the title, type of file and id of the song and i seperated each song with \\n. 然后我有作者,歌曲的标题,文件类型和ID,然后用\\ n分隔每首歌曲。

So after each newline i want to put each of the text into a list. 因此,在每个换行符之后,我想将每个文本放入列表中。

Also if you see any where in my code that i could improve please tell me. 另外,如果您发现我的代码中有任何地方需要改进,请告诉我。

and the string i want to seperate is: 我想分开的字符串是:

'\\' = '\\'=

author : "Noah and the whale",title : "Lifegoeson",type : "sound",file : "http://www.themusiciv.com/wp-content/uploads/2011/02/LIFEGOESON.mp3",id : "efca2792fc0dc9c076e5ef96c6b88d62" }, 作者:“诺亚与鲸鱼”,标题:“ Lifegoeson”,类型:“声音”,文件:“ http://www.themusiciv.com/wp-content/uploads/2011/02/LIFEGOESON.mp3”,id :“ efca2792fc0dc9c076e5ef96c6b88d62”},

author : "Noah and the whale",title : "Lifegoeson",type : "sound",file : "http://www.maestrobilly.com/SFTMCHN/natw_lgo.mp3",id : "8da985a2a5757f3e54c20341a01a2a3e" }, 作者:“诺亚与鲸鱼”,标题:“ Lifegoeson”,类型:“声音”,文件:“ http://www.maestrobilly.com/SFTMCHN/natw_lgo.mp3”,id:“ 8da985a2a5757f3e54c20341a01a2a3e”},

author : "Noah and the whale",title : "Stranger",type : "sound",file : "http://www.tittletunes.com/wp-content/uploads/08%20Stranger.mp3",id : "473f4056c8ca5afb61677b86cda7ce82" }, 作者:“诺亚与鲸鱼”,标题:“陌生人”,类型:“声音”,文件:“ http://www.tittletunes.com/wp-content/uploads/08%20Stranger.mp3”,id:“ 473f4056c8ca5afb61677b86cda7ce82“},

author : "Noah and the whale",title : "Mary",type : "sound",file : "http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008%5d%5bCD+SkidVid_XviD+Cov%5d/10%20%20Noah%20And%20The%20Whale%20-%20Mary.mp3",id : "824ef3d3d87088cebc18205cf02187f3" }, 作者:“诺亚与鲸鱼”,标题:“玛丽”,类型:“声音”,文件:“ http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008 %5d%5bCD + SkidVid_XviD + Cov%5d / 10%20%20Noah%20And%20The%20Whale%20-%20Mary.mp3“,id:” 824ef3d3d87088cebc18205cf02187f3“},

author : "Noah and the whale",title : "Lifegoeson",type : "sound",file : "http://www.directcurrentmusic.com/storage/mp3s-11/noah%20%20the%20whale%20-%20l.ifegoeson.mp3",id : "92765bf124a4575950293ac24181daed" }, 作者:“诺亚与鲸鱼”,标题:“ Lifegoeson”,类型:“声音”,文件:“ http://www.directcurrentmusic.com/storage/mp3s-11/noah%20%20the%20whale%20- %20l.ifegoeson.mp3“,id:” 92765bf124a4575950293ac24181daed“},

author : "Noah and the whale",title : "Jocasta",type : "sound",file : "http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008%5d%5bCD+SkidVid_XviD+Cov%5d/02%20%20Noah%20And%20The%20Whale%20-%20Jocasta.mp3",id : "230b4eaea4bc076e4aa71e0722dfd294" }, 作者:“诺亚与鲸鱼”,标题:“约卡斯塔”,类型:“声音”,文件:“ http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008 %5d%5bCD + SkidVid_XviD + Cov%5d / 02%20%20Noah%20And%20The%20Whale%20-%20Jocasta.mp3“,id:” 230b4eaea4bc076e4aa71e0722dfd294“},

author : "Noah and the whale",title : "Atoms in a molecule",type : "sound",file : "http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008%5d%5bCD+SkidVid_XviD+Cov%5d/01%20%20Noah%20And%20The%20Whale%20-%202%20Atoms%20In%20A%20Molecule.mp3",id : "1b078ccba9a0cd060723a6aeb6f475f7" }, 作者:“诺亚与鲸鱼”,标题:“分子中的原子”,类型:“声音”,文件:“ http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful- -%5b2008%5d%5bCD + SkidVid_XviD + Cov%5d / 01%20%20Noah%20And%20The%20Whale%20-%202%20Atoms%20In%20A%20Molecule.mp3“,id:” 1b078ccba9a0cd060723a6aeb}

author : "Noah and the whale",title : "Rocks and daggers",type : "sound",file : "http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful--%5b2008%5d%5bCD+SkidVid_XviD+Cov%5d/08%20%20Noah%20And%20The%20Whale%20-%20Rocks%20And%20Daggers.mp3",id : "3b8b6bb05150b29dadcd183cb6ff8f48" }, 作者:“诺亚与鲸鱼”,标题:“岩石和匕首”,类型:“声音”,文件:“ http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful-- %5b2008%5d%5bCD + SkidVid_XviD + Cov%5d / 08%20%20Noah%20And%20The%20Whale%20-%20Rocks%20And%20Daggers.mp3“,id:” 3b8b6bb05150b29dadcd183cb6ff8f48“},

author : "Noah and the whale",title : "Rocks and daggers",type : "sound",file : "http://earitnow.com/uploads/mp3s/noahandthewhale/05-noah_and_the_whale-rocks_and_daggers.mp3",id : "b67153c57290f324576ec0aca73e8f32" }, 作者:“诺亚与鲸鱼”,标题:“岩石和匕首”,类型:“声音”,文件:“ http://earitnow.com/uploads/mp3s/noahandthewhale/05-noah_and_the_whale-rocks_and_daggers.mp3”,id :“ b67153c57290f324576ec0aca73e8f32”},

author : "Noah and the whale",title : "Mary",type : "sound",file : "http://www.rcdc.it/audio/maps/Audio//Noah And The Whale - Mary.mp3",id : "6428201fca47fa66a902fc6779992e2e" ' 作者:“诺亚与鲸鱼”,标题:“玛丽”,类型:“声音”,文件:“ http://www.rcdc.it/audio/maps/Audio//诺亚与鲸鱼-Mary.mp3” ,id:“ 6428201fca47fa66a902fc6779992e2e”'

A quick hack would be something like 快速破解就像

# x is your string
import re
parsed = re.findall('author : "([^"]+)",title : "([^"]+)",type : "([^"]+)",file : "([^"]+)",id : "([^"]+)', x)
print parsed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM