2016-09-29 3 views
0

XML 형식으로 일부 웹 사이트를 다운로드하기 위해 API에 연결 중입니다. Jupyter 환경에서 BeautifulSoup를 사용합니다. 데이터에 액세스하는 데이 코드를 활용하고 있습니다 ...BeautifulSoup xml write()시 데이터 없음

이 코드를 사용하면 XML 형식의 웹 사이트를 당길 수 있습니다. 다음은 XML의 예 ... 나는 각 requests.get 10 개 결과를 당기는거야

<result> 
    <title>Sepsis Alliance</title> 
    <contentType>html</contentType> 
    <sum>... and Sepsis Alliance has introduced new and exciting ways for individuals, medical ... industry partners and other organizations to help shine the spotlight on sepsis. ... Spike Out Sepsis. Columbus, OH. July 23, 2016. 3rd Annual Jeffrey Ray Davis Sepsis ... Sepsis Alliance News. June 4, 2016. Sepsis Alliance Mourns Loss of Boxing Legend Muhammad ...</sum> 
    <url>www.sepsisalliance.org</url>... 

이다. 이 xml 요청을 내 하드 드라이브의 .xml 파일에 저장하여 RStudio에서 더 잘 작동 할 필요가 있습니다. 나는 ...

soup = str(soup)  
file_out = open('text_mining.xml', 'a') 
file_out.write(soup) 
file_out.close() 

난 데 문제는 내 보낸 xml 파일 내부의 태그과 같이 비어 있다는 것입니다

... 파일을 저장하려면 다음 코드를 사용하고있어

<result> 
<title></title> 
<contenttype></contenttype> 
<sum></sum> 
<url></url> 
<hopcount>0</hopcount> 
<size></size> 

몇 가지 해결책이 있습니까?

답변

0

내 버그를 찾았습니다. 이 코드 줄에서 w에 대한 a 플래그를 변경해야했습니다 ...

file_out = open('text_mining.xml', 'a') # before 
file_out = open('text_mining.xml', 'w') # after