Python で次の構文エラーが発生します。
SyntaxError: 'return' outside function
それは自明のように思えますが、私が見る限り、return は関数内にあります。
これが私のコードです:
def getLinks(self, url, fandom, soup):
links = []
searchElementDict = {
'aff':'select', 'fcwd':'select', 'ffn':'select', 'tthm':'select', 'lua':'select', 'ffa':'select',
'hpfd':'select', 'phns':'select', 'mbba':'div', 'avgf':'div', 'mugn':'select', 'hpffa':'select',
'hpff':'select',
}
if fandom in searchElementDict:
searchElement = searchElementDict[fandom]
searchElementForDict = {
'aff':'name', 'fcwd':'name', 'ffn':'title', 'tthm':'name', 'lua':'class', 'ffa':'class',
'hpfd':'name', 'phns':'name', 'mbba':'id', 'avgf':'id', 'mugn':'name', 'hpffa':'name',
'hppf':'name',
}
if fandom in searchElementForDict:
searchElementFor = searchElementForDict[fandom]
withValueDict = {
'aff':'chapnav', 'fcwd':'goto', 'ffn':'Chapter Navigation', 'tthm':'chapnav', 'lua':'textbox',
'ffa':'locationSelect', 'hpfd':'sid', 'phns':'chao', 'mbba':'mibba-layout-parts', 'avgf':'chapters',
'mugn':'chapter', 'hpffa':'chapter', 'hpff':'chapterid',
}
if fandom in withValueDict:
withValue = withValueDict[fandom]
try:
if fandom == 'mbba' or fandom == 'avgf':
chapterGroup = soup.find(searchElement, attrs={searchElementFor : withValue})
individualChapters = chapterGroup.findAll('a')
for each in individualChapters:
chapterLink = each['href']
links.append(chapterLink)
else:
chapterGroup = soup.find(searchElement, attrs={searchElementFor : withValue})
individualChapters = chapterGroup.findAll('option', attrs={'value=':''})
for each in individualChapters:
chapterLink = each.get('value')
links.append(chapterLink)
if fandom == 'fcwd':
del links[0]
elif fandom == 'hpfd' or fandom == 'hpff':
del links[0]
del links[0]
except:
links.append(1)
return links
私は明らかに何かが欠けています.何がわからないのですか.