我试着学习python,因此编写了一个小刮刀。 我走得很远,但是在连接字符串方面遇到了问题。
我的计划是只在将我们的函数作为参数给出时添加think。代码如下所示:
def buildUrl(self, artist, album=None, title=None):
url = self.url + urllib.quote(artist)
if title is not None: url = url + '/' + urllib.quote(album)
if album is not None: url = url + '/' + urllib.quote(title)
return url
现在问题是我收到以下错误:
File "C:\Users\lony\workspace-python\scrapper\bs.py", line 22, in buildUrl
if title is not None: url = url + '/' + urllib.quote(album)
File "C:\Program Files (x86)\Python27\lib\urllib.py", line 1269, in quote
raise TypeError('None object cannot be quoted')
TypeError: None object cannot be quoted
我做错了什么?
答案 0 :(得分:0)
您的if
条件不匹配:
if title is not None: url = url + '/' + urllib.quote(album)
^^^^^ ^^^^^