我尝试将从网页的html代码中提取的beautifulsoup的结果导出到文本文件,但我不能,它在文件中写了我的€XL。我认为它应该将结果转换为可读文本,但我不知道如何。
以下是代码:
from bs4 import BeautifulSoup
from urllib.request import urlopen
pageFile = urlopen("exemple of url")
pageHtml = pageFile.read()
soup = BeautifulSoup(pageHtml,"html.parser")
myfile.close()
Sdef = soup.findAll('li',class_='exemple_class')
len(Sdef)
Sdef[0].text
Sdef[0].attrs
for t in Sdef:
print(t.text)
with open("output_file","wb") as file:
import sys
sys.setrecursionlimit(50000)
import pickle
pickle = pickle.Pickler(file)
pickle.dump(t.text)