所以我有代码
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
然后我有作者,标题,文件类型和歌曲的ID,我用\ n分隔每首歌。
因此,在每个换行符后,我想将每个文本放入列表中。
另外,如果您在我的代码中看到我可以改进的地方,请告诉我。
我要分开的字符串是:
'\'=
作者:“诺亚和鲸鱼”,标题:“Lifegoeson”,输入:“声音”,档案:“http://www.themusiciv.com/wp-content/uploads/2011/02/LIFEGOESON.mp3 “,id:”efca2792fc0dc9c076e5ef96c6b88d62“},
作者:“诺亚和鲸鱼”,标题:“Lifegoeson”,输入:“声音”,文件:“http://www.maestrobilly.com/SFTMCHN/natw_lgo.mp3",id:”8da985a2a5757f3e54c20341a01a2a3e“} ,
作者:“诺亚和鲸鱼”,标题:“陌生人”,输入:“声音”,档案:“http://www.tittletunes.com/wp-content/uploads/08%20Stranger.mp3”, id:“473f4056c8ca5afb61677b86cda7ce82”},
作者:“诺亚和鲸鱼”,标题:“玛丽”,输入:“声音”,档案:“http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful- - %5b2008%5d%5bCD + SkidVid_XviD + Cov%5d / 10%20%20Noah%20A%20%20Whale%20-%20Mary.mp3“,id:”824ef3d3d87088cebc18205cf02187f3“},
作者:“诺亚和鲸鱼”,标题:“Lifegoeson”,输入:“声音”,档案:“http://www.directcurrentmusic.com/storage/mp3s-11/noah%20%20the%20whale %20-%20l.ifegoeson.mp3“,id:”92765bf124a4575950293ac24181daed“},
作者:“诺亚和鲸鱼”,标题:“Jocasta”,输入:“声音”,档案:“http://veradio.com/sounds/Noah%20And%20The%20Whale%20-%20Peaceful- - %5b2008%5d%5bCD + SkidVid_XviD + Cov%5d / 02%20%20Noah%20A%20%20Whale%20-%20Jocasta.mp3“,id:”230b4eaea4bc076e4aa71e0722dfd294“},
作者:“诺亚和鲸鱼”,标题:“分子中的原子”,输入:“声音”,文件:“http://veradio.com/sounds/Noah%20And%20The%20Whale%20- %20Peaceful - %5b2008%5d%5bCD + SkidVid_XviD + Cov%5d / 01%20%20Noah%20A%20%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 / 08%20%20Noah%20A%20%20Whale%20-%20Rocks%20A%20Daggers.mp3“,id:”3b8b6bb05150b29dadcd183cb6ff8f48“},
作者:“诺亚和鲸鱼”,标题:“岩石和匕首”,输入:“声音”,文件:“http://earitnow.com/uploads/mp3s/noahandthewhale/05-noah_and_the_whale-rocks_and_daggers.mp3 “,id:”b67153c57290f324576ec0aca73e8f32“},
作者:“诺亚和鲸鱼”,标题:“玛丽”,输入:“声音”,档案:“http://www.rcdc.it/audio/maps/Audio//Noah和鲸鱼 - 玛丽.mp3“,id:”6428201fca47fa66a902fc6779992e2e“'
答案 0 :(得分:0)
快速破解就像是
# x is your string
import re
parsed = re.findall('author : "([^"]+)",title : "([^"]+)",type : "([^"]+)",file : "([^"]+)",id : "([^"]+)', x)
print parsed