[問題] 不知道是哪邊出了問題 求救
剛學python不到1個月
嘗試用python抓點資料
print爬取出來都很正常
但是要儲存資料時卻出現了
UnicodeEncodeError: 'cp950' codec can't encode character '\u5367' in position
2763: illegal multibyte sequence
請問一下這是哪邊出了問題?
有解決的方法嗎?
以下是程式碼:
import requests
from bs4 import BeautifulSoup
import lxml
u="https://zh.wikisource.org/wiki/%E9%87%91%E7%93%B6%E6%A2%85/%E7%AC%AC01%E5%9B%9E"
res2=requests.get(u)
soup=BeautifulSoup(res2.text,"lxml")
data=soup.select("#mw-content-text")[0].text
titles=(soup.select("td ")[2].text[4:-8].strip())
loca="D:\\bigdata\\testR\\word\\金瓶梅\\"+titles+".txt"
with open(loca,"w") as my_file:
my_file.write(data)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.26.81.29
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1455439229.A.059.html
→
02/14 16:43, , 1F
02/14 16:43, 1F
→
02/14 16:48, , 2F
02/14 16:48, 2F
→
02/14 16:49, , 3F
02/14 16:49, 3F
→
02/14 16:52, , 4F
02/14 16:52, 4F
→
02/14 16:53, , 5F
02/14 16:53, 5F
Python 近期熱門文章
PTT數位生活區 即時熱門文章