使用api,我将获得xml文件和XPos,YPos等地理信息。但我的xml解析有问题。
from urllib.request import Request, urlopen
import xml.etree.ElementTree as ET
request = Request(url + queryParams)
request.get_method = lambda: 'GET'
response = urlopen(request)
string = str(response, 'utf-8')
和字符串在下面。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><header><resultCode>00</resultCode><resultMsg>NORMAL SERVICE.</resultMsg></header><body><items><item><addr>부산광역시 부산진구 복지로 75 지하2~지상10층 (개금동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>395</drTotCnt><estbDd>19790601</estbDd><gdrCnt>5</gdrCnt><intnCnt>36</intnCnt><postNo>47392</postNo><resdntCnt>156</resdntCnt><sdrCnt>198</sdrCnt><sgguCd>210004</sgguCd><sgguCdNm>부산진구</sgguCdNm><sidoCd>210000</sidoCd><sidoCdNm>부산</sidoCdNm><telno>051-890-6212</telno><XPos>129.020571507</XPos><YPos>35.1464544697</YPos><yadmNm>(학교법인)인제대학교부산백병원</yadmNm><ykiho>JDQ4MTAxMiM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ3OSQzNjEyMjIjNTEjJDEjJDYjJDgz</ykiho></item><item><addr>인천광역시 부평구 동수로 56 (부평동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>278</drTotCnt><estbDd>19810806</estbDd><gdrCnt>1</gdrCnt><hospUrl>http://www.cmcism.or.kr/</hospUrl><intnCnt>21</intnCnt><postNo>21431</postNo><resdntCnt>79</resdntCnt><sdrCnt>177</sdrCnt><sgguCd>220003</sgguCd><sgguCdNm>인천부평구</sgguCdNm><sidoCd>220000</sidoCd><sidoCdNm>인천</sidoCdNm><telno>032-1544-9004</telno><XPos>126.725205401</XPos><YPos>37.4841315437</YPos><yadmNm>가톨릭대학교인천성모병원</yadmNm><ykiho>JDQ4MTYyMiM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ3OSQyNjE4MzIjNDEjJDEjJDgjJDgz</ykiho></item><item><addr>서울특별시 종로구 새문안로 29 (평동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>375</drTotCnt><estbDd>19790324</estbDd><gdrCnt>5</gdrCnt><hospUrl>http://www.kbsmc.co.kr</hospUrl><intnCnt>30</intnCnt><postNo>03181</postNo><resdntCnt>146</resdntCnt><sdrCnt>194</sdrCnt><sgguCd>110016</sgguCd><sgguCdNm>종로구</sgguCdNm><sidoCd>110000</sidoCd><sidoCdNm>서울</sidoCdNm><telno>02-2001-2001</telno><XPos>126.967812251</XPos><YPos>37.5688670052</YPos><yadmNm>강북삼성병원</yadmNm><ykiho>JDQ4MTg4MSM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ3OSQ0NjEwMDIjNjEjJDEjJDQjJDgz</ykiho></item><item><addr>서울특별시 광진구 능동로 120-1 (화양동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>444</drTotCnt><estbDd>19821116</estbDd><gdrCnt>4</gdrCnt><hospUrl>http://www.kuh.ac.kr</hospUrl><intnCnt>38</intnCnt><postNo>05030</postNo><resdntCnt>172</resdntCnt><sdrCnt>230</sdrCnt><sgguCd>110023</sgguCd><sgguCdNm>광진구</sgguCdNm><sidoCd>110000</sidoCd><sidoCdNm>서울</sidoCdNm><telno>1588-1533</telno><XPos>127.072055109</XPos><YPos>37.5412356321</YPos><yadmNm>건국대학교병원</yadmNm><ykiho>JDQ4MTg4MSM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ2MiQyNjE4MzIjNjEjJDEjJDQjJDgz</ykiho></item><item><addr>대구광역시 중구 동덕로 130 (삼덕동2가, 경북대학교병원)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>545</drTotCnt><estbDd>19100907</estbDd><gdrCnt>6</gdrCnt><hospUrl>http://knumc.knu.ac.kr</hospUrl><intnCnt>85</intnCnt><postNo>41944</postNo><resdntCnt>222</resdntCnt><sdrCnt>232</sdrCnt><sgguCd>230006</sgguCd><sgguCdNm>대구중구</sgguCdNm><sidoCd>230000</sidoCd><sidoCdNm>대구</sidoCdNm><telno>422-1141</telno><XPos>128.604314661</XPos><YPos>35.8662354972</YPos><yadmNm>경북대학교병원</yadmNm><ykiho>JDQ4MTYyMiM4MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ3OSQyNjEwMDIjNzEjJDEjJDgjJDgz</ykiho></item><item><addr>경상남도 진주시 강남로 79 (칠암동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>326</drTotCnt><estbDd>19861013</estbDd><gdrCnt>1</gdrCnt><hospUrl>http://www.gnuh.co.kr/</hospUrl><intnCnt>22</intnCnt><postNo>52727</postNo><resdntCnt>121</resdntCnt><sdrCnt>182</sdrCnt><sgguCd>380500</sgguCd><sgguCdNm>진주시</sgguCdNm><sidoCd>380000</sidoCd><sidoCdNm>경남</sidoCdNm><telno>055-750-8000</telno><XPos>128.096026987</XPos><YPos>35.1753899647</YPos><yadmNm>경상대학교병원</yadmNm><ykiho>JDQ4MTYyMiM4MSMkMSMkNCMkODkkMzgxMzUxIzExIyQxIyQzIyQ5OSQyNjEwMDIjNjEjJDEjJDQjJDgz</ykiho></item><item><addr>서울특별시 동대문구 경희대로 23 (회기동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>412</drTotCnt><estbDd>19711005</estbDd><gdrCnt>5</gdrCnt><hospUrl>http://www.khuh.or.kr/</hospUrl><intnCnt>106</intnCnt><postNo>02447</postNo><resdntCnt>87</resdntCnt><sdrCnt>214</sdrCnt><sgguCd>110007</sgguCd><sgguCdNm>동대문구</sgguCdNm><sidoCd>110000</sidoCd><sidoCdNm>서울</sidoCdNm><telno>02-958-8114</telno><XPos>127.050741243</XPos><YPos>37.5937747637</YPos><yadmNm>경희대학교병원</yadmNm><ykiho>JDQ4MTg4MSM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ4OSQzNjEyMjIjODEjJDEjJDIjJDgz</ykiho></item><item><addr>대구광역시 중구 달성로 56 (동산동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>427</drTotCnt><estbDd>19680406</estbDd><gdrCnt>3</gdrCnt><hospUrl>http://www.dsmc.or.kr/</hospUrl><intnCnt>36</intnCnt><postNo>41931</postNo><resdntCnt>154</resdntCnt><sdrCnt>234</sdrCnt><sgguCd>230006</sgguCd><sgguCdNm>대구중구</sgguCdNm><sidoCd>230000</sidoCd><sidoCdNm>대구</sidoCdNm><telno>250-7114</telno><XPos>128.582521394</XPos><YPos>35.8701796577</YPos><yadmNm>계명대학교동산병원</yadmNm><ykiho>JDQ4MTYyMiM4MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ3OSQyNjEyMjIjNjEjJDEjJDQjJDgz</ykiho></item><item><addr>서울특별시 구로구 구로동로 148 (구로동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>498</drTotCnt><estbDd>19830831</estbDd><gdrCnt>5</gdrCnt><hospUrl>http://guro.kumc.or.kr/main/index.do</hospUrl><intnCnt>42</intnCnt><postNo>152703</postNo><resdntCnt>175</resdntCnt><sdrCnt>276</sdrCnt><sgguCd>110005</sgguCd><sgguCdNm>구로구</sgguCdNm><sidoCd>110000</sidoCd><sidoCdNm>서울</sidoCdNm><telno>02-2626-1114</telno><XPos>126.884639554</XPos><YPos>37.4911811753</YPos><yadmNm>고려대학교의과대학부속구로병원</yadmNm><ykiho>JDQ4MTg4MSM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ2MiQ0NjEwMDIjNjEjJDEjJDAjJDgz</ykiho></item><item><addr>경기도 안산시 단원구 적금로 123 (고잔동)</addr><clCd>01</clCd><clCdNm>상급종합</clCdNm><drTotCnt>281</drTotCnt><estbDd>19860101</estbDd><gdrCnt>2</gdrCnt><hospUrl>http://ansan.kumc.or.kr/main/index.do</hospUrl><intnCnt>0</intnCnt><postNo>15355</postNo><resdntCnt>82</resdntCnt><sdrCnt>197</sdrCnt><sgguCd>311101</sgguCd><sgguCdNm>안산단원구</sgguCdNm><sidoCd>310000</sidoCd><sidoCdNm>경기</sidoCdNm><telno>031-412-5653</telno><XPos>126.824997324</XPos><YPos>37.3188581763</YPos><yadmNm>고려대학교의과대학부속안산병원</yadmNm><ykiho>JDQ4MTYyMiM1MSMkMSMkMCMkODkkMzgxMzUxIzExIyQxIyQzIyQ5OSQzNjEwMDIjNTEjJDEjJDIjJDgz</ykiho></item></items><numOfRows>10</numOfRows><pageNo>1</pageNo><totalCount>69847</totalCount></body></response>'
xmldata = ET.fromstring(string)
xmldata.findall('XPos')
>>> []
我得到了这个空列表。 我不知道为什么我得到这个无变量。
答案 0 :(得分:0)
您需要使用XPath语法:
xmldata.findall('.//XPos')