Python 如何使函数自身重复
我有一个python问题,我正在阅读XML,并设置了两个扩展函数;一个函数查找位置,而另一个函数查找第一个函数中的位置,并返回信息。我的问题是,我需要这一点继续向下的页面,并找到其他出现的每一个。我不确定这是否是一个很好的解释,所以下面是代码:Python 如何使函数自身重复,python,Python,我有一个python问题,我正在阅读XML,并设置了两个扩展函数;一个函数查找位置,而另一个函数查找第一个函数中的位置,并返回信息。我的问题是,我需要这一点继续向下的页面,并找到其他出现的每一个。我不确定这是否是一个很好的解释,所以下面是代码: def findEntryTag(webPage): start= webPage.find("<entry>") +7 end= webPage.find("</entry>") slicedString=webPage[
def findEntryTag(webPage):
start= webPage.find("<entry>") +7
end= webPage.find("</entry>")
slicedString=webPage[start:end]
return slicedString
def findEarthquake(webPage):
slicedString=findEntryTag(webPage)
start= slicedString.find("<title>") +7
end= slicedString.find("</title>")
eq= slicedString[start:end]
return eq
my Earthquake= findEarthquake(text)
print (myEarthquake)
def findEntryTag(网页):
开始=网页。查找(“”+7
结束=网页。查找(“”)
slicedString=网页[开始:结束]
返回切片字符串
def findEarthquake(网页):
slicedString=findEntryTag(网页)
开始=切片字符串。查找(“”+7
end=slicedString.find(“”)
eq=切片字符串[开始:结束]
返回均衡器
我的地震=findEarthquake(文本)
打印(我的地震)
所以需要它再次执行这些功能以获得另一次地震,并打印出它们的孔列表。请帮忙!谢谢不要尝试手动解析XML。有很多很好的方法,包括标准库中的
ElementTree
。不要尝试手动解析XML。有很多很好的方法可以做到这一点,包括标准库中的ElementTree
。lxml.etree使这一点非常好用
对于结构如此的XML文档:
<entry>
<title>story 1</title>
<text>this is the first earthquake story</text>
<title>story 2</title>
<text>this is the second earthquake story</text>
<title>story 3</title>
<text>this is the third earthquake story</text>
</entry>
(摘自上的示例)
结果如下所示:
title - story 1
title - story 2
title - story 3
调味 lxml.etree使这项工作变得很好 对于结构如此的XML文档:
<entry>
<title>story 1</title>
<text>this is the first earthquake story</text>
<title>story 2</title>
<text>this is the second earthquake story</text>
<title>story 3</title>
<text>this is the third earthquake story</text>
</entry>
(摘自上的示例)
结果如下所示:
title - story 1
title - story 2
title - story 3
调味 ElementTree很棒!另外,xml.sax是标准libraryElementTree中的一个好工具,非常棒!另外,xml.sax是标准库中的一个好工具