我的目标是从xml文档(链接)中提取URL并将其放入列表中: https://www.valuespreadsheet.com/iedgar/results.php?stock=NFLX&output=xml
我从lxml
导入了etree
,并创建了一个从所有<instanceUrl>
标记中提取文本的列表理解。你知道吗
url = 'https://valuespreadsheet.com/iedgar/results.php?stock=NFLX&output=xml'
et = etree.fromstring(urlopen(url).read())
return [_.find('instanceUrl').text for _ in et.find('filings')]
现在,我想限制列表,以便它只从<instanceUrl>
标记中提取文本,其中<formType>
=10K
我怎样才能做到这一点?你知道吗
你需要一个XPath expression and the ^{} method :
这里我们用
10-K
文本过滤包含formType
子节点的filing
节点,然后得到instanceUrl
子节点。你知道吗请注意,
_
变量名用于丢弃变量-必须定义但未实际使用的变量(例如在解包期间)。在你的情况下,你实际上已经用过了。你知道吗相关问题 更多 >
编程相关推荐