我正在尝试读取标签中的所有链接,然后尝试从中创建 wiki 链接...基本上我想从 xml 文件中读取每个链接,然后使用最后一个单词创建 wiki 链接(请参阅下面的内容我的意思是链接的最后一个字)...由于某种原因遇到以下错误,我缺少什么,请建议
http://wiki.build.com/ca_builds/CIT (last word is CIT)
http://wiki.build.com/ca_builds/1.2_Archive(last word is 1.2_Archive)
输入 XML:-
<returnLink>
http://wiki.build.com/ca_builds/CIT
http://wiki.build.com/ca_builds/1.2_Archive
</returnLink>
蟒蛇代码
def getReturnLink(xml):
"""Collects the link to return to the PL home page from the config file."""
if xml.find('<returnLink>') == -1:
return None
else:
linkStart=xml.find('<returnLink>')
linkEnd=xml.find('</returnLink>')
link=xml[linkStart+12:linkEnd].strip()
link = link.split('\n')
#if link.find('.com') == -1:
#return None
for line in link:
line = line.strip()
print "LINE"
print line
lastword = line.rfind('/') + 1
line = '['+link+' lastword]<br>'
linklis.append(line)
return linklis
输出:-
line = '['+link+' lastword]<br>'
TypeError: cannot concatenate 'str' and 'list' objects
预期输出:-
CIT (this will point to http://wiki.build.com/ca_builds/CIT
1.2_Archive (this will point to http://wiki.build.com/ca_builds/1.2_Archive 1.2_Archive)