io - writing Beautiful Soup output to a file -
okay i'm having issue writing extracted information want file. tested simple print statement , giving exact output want. however. when attempt write information file writes nothing , file shows empty
the input wiki file in xml format , list of strings corresponding page titles wish pull out of wiki file. here code, page_titles list ['anarchism','adam , eve', ...] :
new_wiki = open('new_wiki.xml', 'w') soup = beautifulsoup(wiki) wiki_page = soup.find_all('page') item in wiki_page: title = item.title.get_text() if title in page_titles: new_wiki.write('\n' % (item))
this might sound silly, did forget new_wiki.close()
?
Comments
Post a Comment