Привет! Я использую python 3 BeautifulSoup, чтобы попытаться извлечь ссылку. Он работает большую часть времени, но время от времени не может найти схему.
Код, который у меня есть, выглядит следующим образом (часть большего тела):
self.schema = self.soup.find(['link:schemaRef', 'schemaRef']).get('xlink:href')
self.namespaces = {}
for k in self.soup.find('html').attrs:
if k.startswith("xmlns") or ":" in k:
self.namespaces[k] = self.soup.find('html')[k].split(" ")
не находит проблем схема такого рода вещей:
<ix:references>
<link:schemaRef xlink:type="simple" xlink:href="https://xbrl.frc.org.uk/FRS-102/2014-09-01/FRS-102-2014-09-01.xsd" />
</ix:references>
, но она не может найти xlink: href в следующих:
<references>
<schemaRef xlink:href="https://xbrl.frc.org.uk/FRS-102/2014-09-01/FRS-102-2014-09-01.xsd" xlink:type="simple" xmlns="http://www.xbrl.org/2003/linkbase"/>
</references>
Я получаю ошибку:
AttributeError Traceback (most recent call last)
<ipython-input-8-da0992ab9ae8> in <module>
96
97 with open(filename,encoding="utf8") as a:
---> 98 x = Parser(a)
99 r = json.dumps(x.to_table(), indent=4)
100 jsondata = json.loads(r)
~\OneDrive\Desktop\parser\core.py in __init__(self, f, raise_on_error)
21 self.errors = []
22
---> 23 self._get_schema()
24
25 self._get_contexts()
~\OneDrive\Desktop\parser\core.py in _get_schema(self)
47 self.schema = self.soup.find(
48
---> 49 ['link:schemaRef', 'schemaRef']).get('xlink:href')
50
51 self.namespaces = {}
AttributeError: 'NoneType' object has no attribute 'get'
Любая помощь будет высоко ценится
Спасибо.