Jun-04-2018, 11:34 PM
(This post was last modified: Jun-04-2018, 11:34 PM by RajaPython.)
Hi Snippat,
In my XML file i have below data, multiple object having similar data with different object IDs
<DN>test-1/check-1</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>16365</BYTES_IN>
<BYTES_OUT>1560</BYTES_OUT>
<CONNECTIONS>8</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<EXECUTION_T>525</EXECUTION_T>
<ID>8</ID>
</PMTarget>
</PMMOResult>
<PMMOResult>
<MO dimension="network_element">
<DN>test-1/check-2</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>19935</BYTES_IN>
<BYTES_OUT>1920</BYTES_OUT>
<CONNECTIONS>12</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<ERRORS>0</ERRORS>
<EXECUTION_T>435</EXECUTION_T>
<ID>7</ID>
</PMTarget>
In my XML file i have below data, multiple object having similar data with different object IDs
from bs4 import BeautifulSoup as bsp xml_file=open("E:\\Python\\MyLearning\\TestFiles\\MY.xml", "r+") soup_xml = bsp(xml_file, 'xml') pm=soup_xml.find_all('PMTarget', {'MType':"ABC"}) data=pm.find('ID') print (data)
Error:Traceback (most recent call last):
File "E:/Python/MyLearning/Learning.py", line 230, in <module>
data=pm.find('ID')
File "C:\Python3.6.5\lib\site-packages\bs4\element.py", line 1807, in __getattr__
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
XML FILE:<DN>test-1/check-1</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>16365</BYTES_IN>
<BYTES_OUT>1560</BYTES_OUT>
<CONNECTIONS>8</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<EXECUTION_T>525</EXECUTION_T>
<ID>8</ID>
</PMTarget>
</PMMOResult>
<PMMOResult>
<MO dimension="network_element">
<DN>test-1/check-2</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>19935</BYTES_IN>
<BYTES_OUT>1920</BYTES_OUT>
<CONNECTIONS>12</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<ERRORS>0</ERRORS>
<EXECUTION_T>435</EXECUTION_T>
<ID>7</ID>
</PMTarget>