2015-07-21 18 views
7

CamelCase ve find_all etiket adları olan BeautifulSoup 4.4.0 ile bir xml dosyasını kazıymaya çalışıyorum. Örnek kod:camelCase etiket isimleri ile birlikte BeautifulSoup 4 ile find_all 4

from bs4 import BeautifulSoup 

xml = """ 
<hello> 
    world 
</hello> 
""" 
soup = BeautifulSoup(xml, "lxml") 

for x in soup.find_all("hello"): 
    print x 

xml2 = """ 
<helloWorld> 
    :-) 
</helloWorld> 
""" 
soup = BeautifulSoup(xml2, "lxml") 

for x in soup.find_all("helloWorld"): 
    print x 

alıyorum çıktısı:

$ python soup_test.py 
<hello> 
    world 
</hello> 

kasalı/Büyük harfli etiket adları deve aramak için doğru yolu nedir?

cevap

6

BeautifulSoup kullanarak büyük/küçük harf duyarlı ayrıştırma için "xml" modunda ayrıştırmak isteyebilirsiniz. HTML'nin durumun umurunda olmaması nedeniyle, varsayılan mod (HTML'yi ayrıştırma) durumla ilgili değil. Durumunuzda, "lxml" modunu kullanmak yerine, "xml":