2014-04-22 6 views
1

XML 페이지를 BeautifulSoup으로 파싱하려고하는데 어떤 이유로 XML 파서를 찾을 수 없습니다. 이전에는 XML을 사용하지 않고 페이지를 구문 분석하기 위해 lxml을 사용 했으므로 경로 문제는 아니라고 생각합니다. 여기에 코드입니다 :BeautifulSoup XML 구문 분석이 작동하지 않습니다.

from bs4 import * 
import urllib2 
import lxml 
from lxml import * 


BASE_URL = "http://auctionresults.fcc.gov/Auction_66/Results/xml/round/66_115_database_round.xml" 

proxy = urllib2.ProxyHandler({'http':'http://myProxy.com}) 
opener = urllib2.build_opener(proxy) 
urllib2.install_opener(opener) 
page = urllib2.urlopen(BASE_URL) 

soup = BeautifulSoup(page,"xml") 

print soup 

아마 간단하게 뭔가를보고 싶어하지만, 모든 XML 내가 여기에 발견 BS3 주위에 있었다 BS 질문에 대한 구문 분석 내가 XML을 구문 분석을위한 다른 방법을 사용 BS4을 사용하고 있습니다. 감사.

답변

1

lxml이 설치되어있는 경우, 아래와 같이 BeautifulSoup의 파서로 전화하면됩니다.

코드 :

from bs4 import BeautifulSoup as bsoup 
import requests as rq 

url = "http://auctionresults.fcc.gov/Auction_66/Results/xml/round/66_115_database_round.xml" 
r = rq.get(url) 

soup = bsoup(r.content, "lxml") 
print soup 

결과 :

<html><body><dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:nonamespaceschemalocation="66_database.xsd"><all_bids> 
<auction_id>66</auction_id> 
<auction_description>Advanced Wireless Services</auction_description> 
... really long list follows... 
[Finished in 34.9s] 

이 도움이되는지 알려 주시기 바랍니다.

+0

iPython에서는 작동하지만 Eclipse PyDev에서는 작동하지 않으므로 경로 문제 여야합니다. 나는 그것을 소트 할 것이다. 팁 고마워. – TomR

+0

그건 좀 이상해. 그래도 문제의 근원을 알았 기 때문에 기쁩니다. 어쨌든 위의 대답은 해결 방법으로 잘 작동합니다. :) – Manhattan

관련 문제