Reputation: 317
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
I'm attempting to create a function that will do what the first parsePlayer function does. I'm hoping the playerurls function can take a list and then do a regex function to extract all parts of the string which are in quotations, this is not where I'm having trouble.
I am having trouble in writing the playerurls function. I keep getting this: "exceptions.TypeError: sequence item 0: expected string, NbastatsSpider found" @
sampString = "".join(exlist)
NbastatsSpider is the name of the spider that fills the 'playerurl' field of the item I created. I don't get why I'm getting this error because I'm passing in a list, turning it into a string, doing the regex function to the string and finally returning a list. There must be an error in passing the list (item['playerurl']) to the function. Either that or I'm confusing myself with using the 'self.' parameter.
Upvotes: 0
Views: 78
Reputation: 782693
It should be:
def playerurls(self, exlist):
You need a self
argument because you're calling it as self.playerurls
. You don't need *
before the exlist
argument: that's used when the elements of the list are passed as separate arguments.
I'm not sure why you're using self
in the first place. None of these functions refer to any instance variables of self
.
Upvotes: 2