前提・実現したいこと
Visual studio codeを用いてPythonでwebスクレイピングをし、出力される内容をそのままファイルに書き出すというプログラムを作っています。
以下、参考書参考に入力したプログラムです。
import
1from bs4 import BeautifulSoup 2 3result=requests.get('https://pycon.jp/2016/ja/schedule/talks/list/') 4soup=BeautifulSoup(result.text,'html.parser') 5presentation_html_list=soup.find_all('div',class_='presentation') 6 7with open('web.txt','w') as f: 8 f.write('{0:<10}| {1}\n'.format('language','title')) 9 f.write('{0:<10}| {0}\n'.format('---------')) 10 for presentation_html in presentation_html_list: 11 presentation_title=presentation_html.h3.get_text() 12 13 if '(en)' in presentation_title: 14 language='English' 15 title=presentation_title.replace('(en)','') 16 17 elif '(ja)' in presentation_title: 18 language='Japanese' 19 title=presentation_title.replace('(ja)','') 20 21 f.write('{0:<10}| {1}\n'.format(language,title)) 22コード
web.txtファイルが生成されますが、出力は7.8行目のみで、繰り返し処理が上手くいきません。
発生している問題・エラーメッセージ
エラーメッセージ
UnicodeEncodeError: 'cp932' codec can't encode character '\xa0' in position 72: illegal multibyte sequence
補足情報(FW/ツールのバージョンなど)
windows 8.1 pro
Python3.6.5 使用しています。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/22 07:55