import requests
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_data(self, data):
return data
def criapagina():
r = requests.get('http://shadowcores.twifysoft.net/character.php?name=Sonda+Aquatica')
fo = open('teste.txt', 'w')
fo.write(r.content)
print fo.readline
fo.close()
def lepagina():
fo = open('teste.txt', 'r+')
for line in fo:
parser = MyHTMLParser()
fo.write(parser.feed(line))
fo.close()
lepagina()
我想解析 html 并在读取正确的行后写入文件,例如名称:Sonda 级别:bla bla 但我什至无法将其保存在文件中,因为我收到错误:TypeError:预期字符缓冲区对象