0
내가 어디로 잘못 가고 있는지 간단한 설명을 둘러 보았지만 실제로 찾을 수는 없었습니다. 다음 코드 발췌 :ElementTree XML 구문 분석은 sitemap.org를 반환하기 만합니까?
import time, threading, urllib2, os
import xml.etree.ElementTree as ET
save_path = '/Users/sampeka/Desktop/Programming/SilkySpider/Data'
bloomberg_site_map = urllib2.urlopen('http://www.bloomberg.com/sitemap_news.xml').read()
reuters_site_map = urllib2.urlopen('http://www.reuters.com/sitemap_news_index.xml').read()
def saveXmlFile(data,name):
try:
abs_path = os.path.abspath(save_path)
open_file = open(abs_path+'/'+name,'w')
open_file.write(data)
finally:
open_file.close()
class ParseXML:
def __init__(self,xml_file):
self.xml_file = xml_file
def printStuff(self):
tree = ET.parse(self.xml_file)
root = tree.getroot()
for child in root:
print child.tag, child.attrib
saveXmlFile(bloomberg_site_map,'Bloomberg Site Map.xml')
ParseXML(save_path+'/Bloomberg Site Map.xml').printStuff()
반환이 여러 번 : 난 그냥 간단하게 뭔가가 있어야합니다, 그래서
{http://www.sitemaps.org/schemas/sitemap/0.9}url
{http://www.sitemaps.org/schemas/sitemap/0.9}url
{http://www.sitemaps.org/schemas/sitemap/0.9}url
{http://www.sitemaps.org/schemas/sitemap/0.9}url
{http://www.sitemaps.org/schemas/sitemap/0.9}url
XML은 제대로 저장되고있다. 누군가 이것이 이것이 막히게되는 이유를 설명 할 수 있습니까? 도움을 많이 주셔서 감사합니다.
이 AttributeError를 제기 : '요소'개체가 어떤 속성 'XPath는' –
@samp가 없습니다 : 미안 해요, 내가 사용을'lxml.etree'보다는'lxml.etree .ElementTree'. 이에 따라 답변이 업데이트되었습니다. – isedev