2016-07-04 6 views
0

Ich bezog mich auf eine Lösung auf Stack over Flow in Bezug auf dieses Problem, aber irgendwie funktioniert es immer noch nicht. Es zeigt diesen Fehler:Soup-Objekt zu Textdatei

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 3604: ordinal not in range(128) 

Der Code für das Programm ist:

import urllib 
from bs4 import BeautifulSoup 
fhand = urllib.urlopen('https://en.wikipedia.org/wiki/Michael_Francis_Egan') 
soup = BeautifulSoup(fhand.read()) 
fhand.close() 
f = open("myoutputfile.txt","a") 
f.write(soup.get_text()) 

Antwort

0

ich die Lösung gefunden, wie folgt:

import urllib 
from bs4 import BeautifulSoup 
fhand = urllib.urlopen('https://en.wikipedia.org/wiki/Michael_Francis_Egan') 
soup = BeautifulSoup(fhand).get_text() 
f = open("myoutputfile.txt","w") 
f.write(soup.encode('utf-8'))