Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
какой библиотекой пользуетесь для парсинга?
вообще если совершаемое действие не обязательно 100% выполнится то используется конструкция:
Код:try: data = GetTag(text) except: echo 'Unable to parse tag' data = ''
<UL_ADDRESS DTSTART="28.02.2013" NAMEISPORG="Руководитель">
<VIDADR ID="1" NAME="Адрес исполнительного органа">
</VIDADR>
<ADDRESS INDEKS="644077" DOM="84" KVART="47">
<REGION ID="1100055" NAME="Омская обл" KOD_KL="55">
</REGION>
<GOROD ID="1102823" NAME="Омск г" KOD_KL="55000001000">
</GOROD>
<STREET ID="1560208" NAME="Мира пр-кт" KOD_ST="550000010000739">
</STREET>
</ADDRESS>
</UL_ADDRESS>
for node in tree.iterfind('.//UL_ADDRESS/ADDRESS'):
print node.get('INDEKS'), node.get('DOM'), node.get('KVART')
getchildren()
Deprecated since version 2.7: Use list(elem) or iteration.
[<Element REGION at 0x2561fa8>, <Element GOROD at 0x2561288>, <Element STREET at 0x25612b0>]
[<Element REGION at 0x25612b0>, <Element GOROD at 0x25610a8>, <Element STREET at 0x2561490>]
[<Element REGION at 0x2561490>, <Element GOROD at 0x2561fa8>, <Element STREET at 0x2561a30>]
[<Element REGION at 0x2561490>, <Element GOROD at 0x2561a30>, <Element STREET at 0x25612b0>]
# -*- coding: utf-8 -*-
import lxml.etree as etree
string = """
<UL_ADDRESS DTSTART="28.02.2013" NAMEISPORG="Руководитель">
<VIDADR ID="1" NAME="Адрес исполнительного органа">
</VIDADR>
<ADDRESS INDEKS="644077" DOM="84" KVART="47">
<REGION ID="1100055" NAME="Омская обл" KOD_KL="55">
</REGION>
<GOROD ID="1102823" NAME="Омск г" KOD_KL="55000001000">
</GOROD>
<STREET ID="1560208" NAME="Мира пр-кт" KOD_ST="550000010000739">
</STREET>
</ADDRESS>
</UL_ADDRESS>
"""
tree = etree.fromstring(string)
lol = tree.find('ADDRESS')
print lol
list_of_nodes = list(lol)
print list_of_nodes
for node in list_of_nodes:
for name, value in node.items():
print name, value
<Element ADDRESS at 0x232a8c8>
[<Element REGION at 0x232adc8>, <Element GOROD at 0x232a418>, <Element STREET at 0x232a468>]
ID 1100055
NAME Омская обл
KOD_KL 55
ID 1102823
NAME Омск г
KOD_KL 55000001000
ID 1560208
NAME Мира пр-кт
KOD_ST 550000010000739
Process finished with exit code 0
node.get('KORP')
node.get('KORP').encode('UTF-8')
str(node.get('KORP')).encode('UTF-8')
try:
korp = node.get('OGRN').encode('UTF-8')
except:
korp = ''
print type(node.get('OGRN'))
if type(node.get('OGRN')) == something:
do something