所以我有這樣的代碼:Python語法錯誤問題
from urllib2 import *
import re
alist = []
mu = 'noah and the whale'
mus = mu.replace(' ','-')
op = urlopen('http://en.dilandau.eu/download_music/' + mus + '-1.html')
ops = op.read()
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(']','')
parsed = re.findall('author : "([^"]+)",title : "([^"]+)",type : "([^"]+)",file : "([^"]+)",id : "([^"]+)', vnm)
cvb = ','.join(map(''.join,als)
canada = cvb.split('sound,',1)
song = canada[0]
del canada[0]
run = str(canada)
print run
def download():
url = "http://www.tittletunes.com/wp-content/uploads/08%20Stranger.mp3"
down = urlopen(url)
filepath = 'C:\Users\Psao\Music\Music\dow.mp3'
local = open(filepath, "wb")
local.write(down.read())
但是當我運行出於某種原因的代碼我得到這個錯誤:
line 39 canada = cvbz.split('sound,',1) ^ SyntaxError: invalid syntax
這與用正則表達式解析HTML差不多... – Blender 2011-04-04 05:12:01
除此之外:你的代碼有點垃圾。我們有像htmllib,Beautifulsoup等體面的HTML解析器。你自己解析HTML是廢話。 – 2011-04-04 05:19:51
如果你的代碼是'canada = cvb.split('sound,',1)',canada = cvbz.split('sound,',1)'中出現語法錯誤怎麼辦? – eumiro 2011-04-04 06:27:27