def parsePlayer(self,item,response): #this one works like it should
item['playerurl'] = re.findall(r'"[^"]*"',"".join(item['playerurl']))
print(item['playerurl'])
def parsePlayer(self,item,response): #this one does not work like it should
item['playerurl'] = self.playerurls(item['playerurl'])
print(item['playerurl'])
def playerurls(*exlist):
listed = []
sampString = "".join(exlist)
listed = re.findall(r'"[^"]*"',sampString)
return listed
我正在尝试创建一个函数,它将执行第一个parsePlayer函数所执行的操作。我希望playerURL函数可以获取一个列表,然后使用regex函数来提取字符串中引用的所有部分,这不是我遇到的问题。你知道吗
我在编写playerURL函数时遇到了问题。我一直得到这个:“异常。类型错误:序列项0:应为字符串,找到NbastatsSpider“@
sampString = "".join(exlist)
NbastatsSpider是填充我创建的项的“playerurl”字段的spider的名称。我不明白为什么会出现这个错误,因为我传入了一个列表,把它转换成一个字符串,对字符串执行regex函数,最后返回一个列表。将列表(项['playerurl'])传递给函数时一定有错误。要么我把自己和“self.”参数混淆了。你知道吗
应该是:
您需要一个
self
参数,因为您将其称为self.playerurls
。在exlist
参数之前不需要*
:当列表中的元素作为单独的参数传递时,使用该参数。你知道吗我不知道你为什么要用
self
。这些函数都没有引用self
的任何实例变量。你知道吗相关问题 更多 >
编程相关推荐