python 解析xml(解决gb2312编码问题)

import urllib
import xml.dom.minidom               
url = 'http://223.202.45.187:8080/BillQueryService3/pub/query/billing/LogBandWidthByChannelID?Type=standard&RegionID=9050&ChannelCount=1&StartTime=20130911&EndTime=20130912&ChannelID1=46056'

if __name__ == '__main__':
    response = urllib.urlopen(url).read()
    doc = xml.dom.minidom.parseString(response.replace("GB2312","utf-8"))   
    root  =  doc.documentElement
    nodeList=root.getElementsByTagName("InData") 
    node=nodeList.item(0);
    print node.childNodes[0].nodeValue

<BandWidthDatas>
<InData>734967,804582,748431,700435,741438,790629,711222,785297,760371,879281,830852,667747,521595,591466,523582,596232,525482,521646,585350,590894,471779,495218,501089,522785,568087,516298,592462,560570,559551,663606,591116,532197,502947,587373,657666,564981,789629,892320,861506,666045,513198,516113,556784,382219,543530,852253,870274,626598,578371,581956,502750,561070,647509,609348,700398,556133,558517,1795000,1929277,1930552,1587964,1503018,979172,840592,991367,758422,526656,831452,878502,469387,855522,496229,447473,696246,722823,401733,402657,423735,635378,1540551,1252920,1461867,893117,707067,607637,594154,789271,843980,724784,804936,577846,757652,832049,947499,880607,720087,775329,934759,978645,803068,906384,874214,861754,1565193,1817977,1213644,1465298,1347389,1420933,1536785,1049131,1500526,1549579,1376343,1097279,3230237,2851553,2111527,1835563,1919216,2312424,2282630,2078254,1923741,1760418,2008574,2075676,3067038,3240775,2497667,2561080,2369818,2315820,2178929,1733992,1608287,1482467,1396103,2188629,3102358,2019556,2190123,2565644,2210615,1711603,1814254,1733067,1705588,2024283,1702695,1758020,2020507,1857479,1709575,1568892,1270235,1326908,1532812,1428638,1218445,1424708,1193779,1240165,1346645,1432530,1238506,1362267,1282136,1175855,1248302,1341789,1034955,1259787,961329,1289414,1342310,1174518,1269546,1129377,1102328,1221854,1395323,1590917,1322813,1902681,1308253,1789843,1903007,1369683,1409603,1449242,2380716,1340958,1654614,1317114,1465245,1529357,1591713,1433889,1670220,1618688,1690457,1465408,1379521,1490793,1531951,1455292,1450621,1195069,1401640,1145794,1080168,1175812,1028776,1066365,984952,934138,1040235,1140514,987066,824210,932885,1156897,1175121,965918,1111297,935694,977870,983840,1064438,916079,1069549,1192218,944294,900032,875097,909848,947157,1031544,899517,716283,829213,1198744,934569,822495,1013310,1230587,1050827,1731108,1552921,1397526,1438612,1416353,1424798,1360124,1367022,1266812,1189290,1195439,1270451,1085203,999244,1268162,1081781,986924,1026981,1008771,1021216,919458,921427,1096737,981464,1113669,1010843,802621,1085028,949214,958811,973648,1015204,926723,885322,897739,999079,930218,1114228,798395,739189,724534,770431,690081,666902,694693,1118018,599423,607569,696572,522615,562644,528183,573008,549234,574997,460402,442731,597562,485696,452766,365704,299791,392684,489297,442544,1660053,559529,453975,369781,403340,308204,424640,324732,299929,351675,412267,300087,356539,459041,424110,423831,364746,462399,348210,430134,496612,442855,332628,662960,433334,413039,435819,405867,374756,414264,356662,480472,336633,334113,356180,350322,297548,364154,407945,299995,330622,304129,332683,344510,280522,367045,361366,592740,1646051,394249,347948,349092,326759,385766,499077,371197,323002,411121,396095,419202,386872,425273,432689,371450,668124,474861,705197,828682,672870,675366,813503,795355,836554,733157,990117,765761,944861,1022581,1921460,1992838,1695212,1831779,1541186,1818039,1957435,1646411,1902510,1285266,1552405,1256307,2475268,2456613,1985066,2698468,2832225,2103389,2748432,1751707,1811439,1921550,1609594,1863545,2772701,3436475,3319181,3061922,1836621,2344195,2537610,2341312,2420511,1735777,1705224,1520220,2325041,2214416,2353633,2353664,2286993,1954483,1745312,1502533,2088155,2205358,1485198,1349934,2127168,1931649,1614977,1793171,1356623,1858905,1588347,1282158,1284027,1399066,1400769,1448384,1950174,1446398,1439969,1719046,1473635,1611261,1748211,1519365,1539319,1497638,1524792,1585318,1352348,1418220,1307308,1379955,1245545,1289584,1242751,1131553,1371001,1322266,1086547,1491898,1542348,1832589,1516676,1655508,1464823,1656897,1429998,1414577,1251325,1552593,1202537,1523697,1695120,1970189,1812949,1671501,1479295,1410004,1416660,1626993,1350815,1351374,1342072,1264197,1484656,1170365,1662184,1544690,1288538,1212562,1140891,1155569,1277611,885113,1099045,1125496,1413824,1280331,1368905,1362418,1129078,1333567,1315841,1139785,1108523,1498683,1384885,1101803,1219903,1119834,1246289,1109735,1118365,1095242,1080712,996819,1165898,988801,1025878,896924,1098847,1001020,971911,1224811,876390,843994,838953,1006624,770473,1022543,939497,966504,978833,940519,1033486,773550,901311,922494,826830,920623,1040724,1025869,938946,991959,877955,833190,928697,925425,1680577,1049644,874947,763486,1128969,1107442,875431,934978,903593,819502,743681,621233,917323,</InData>
</BandWidthDatas>

你可能感兴趣的:(python)