1.我试图读取标记“sanity\u results”(查看输入http://pastebin.com/p9H8GQt4)之间的xml文件并打印输出
2.对于包含http://或//的任何行或部分行,我希望它将“a href”超链接标记附加到链接,以便在我发布到电子邮件时,它们在电子邮件中显示为超链接
Input file(results.xml)
http://pastebin.com/p9H8GQt4
def getsanityresults(xmlfile):
srstart=xmlfile.find('<Sanity_Results>')
srend=xmlfile.find('</Sanity_Results>')
sanity_results=xmlfile[srstart+16:srend].strip()
sanity_results = sanity_results.replace('\n','<br>\n')
return sanity_results
def main ():
xmlfile = open('results.xml','r')
contents = xmlfile.read()
testresults=getsanityresults(contents)
print testresults
for line in testresults:
line = line.strip()
//How to find if the line contains "http" or "\\" or "//" and append "a href"attribute
resultslis.append(link)
如果名称=='main': 主()
请查看错误消息:
然后看看
main()
:您正在将open('results.xml', 'r')
的结果输入getsanityresults
。但是open(...)
返回一个文件对象,而getsanityresults
期望xmlfile
是一个字符串。你知道吗您需要提取
xmlfile
的内容,并将其输入到getsanityresults
。你知道吗要获取文件的内容,请阅读[python文档的这一部分]9http://docs.python.org/2/tutorial/inputoutput.html#方法-文件对象)。你知道吗
尤其要尝试:
相关问题 更多 >
编程相关推荐