擅长:python、mysql、java
<p>@Ghislain Fourny:非常感谢。我很高兴知道,我并没有因为发现情况复杂而发疯。现在知道linkbase标签是“自由选择”的,下面是我提出的具体的BeautifulSoup解决方案,以防有人感兴趣:</p>
<pre><code>labeldict = {}
resp = requests.get(calcurl, headers = headers)
ctext = resp.text
soup = BeautifulSoup(ctext, 'lxml')
tags = soup.find_all()
for tag in tags:
if tag.name == 'link:loc':
if tag.has_attr('xlink:href') and tag.has_attr('xlink:label'):
href = tag['xlink:href']
firstsplit = href.split('#')[1] ## gets the part of the link after the pound symbol
value = firstsplit.split('_')[1] ## gets the part after the underscore
key = tag['xlink:label']
labeldict[key] = value
</code></pre>
<p>这将生成一个字典,其中键是“loc_Phil”类型的标签名,值是普通的概念名,例如<code>labeldict['loc_PHILWriteoffOfFinancingCosts'] = 'WriteoffOfFinancingCosts'</code>
这假设xsd链接将始终遵循“…#…"概念”的格式。我还没有找到任何不符合这种格式的,但这不是保证</p>