5
TypeError:PythonやCSVでは「str」ではなく、バイトのようなオブジェクトが必要です
TypeError: 'str'ではなく、バイトのようなオブジェクトが必要です CsvファイルにHTMLテーブルデータを保存するpythonコードの下で実行中に上記のエラーを取得します。rideup.plsの入手方法がわからない。 import csv import requests from bs4 import BeautifulSoup url='http://www.mapsofindia.com/districts-india/' response=requests.get(url) html=response.content soup=BeautifulSoup(html,'html.parser') table=soup.find('table', attrs={'class':'tableizer-table'}) list_of_rows=[] for row in table.findAll('tr')[1:]: list_of_cells=[] for cell in row.findAll('td'): list_of_cells.append(cell.text) list_of_rows.append(list_of_cells) outfile=open('./immates.csv','wb') writer=csv.writer(outfile) writer.writerow(["SNo", "States", "Dist", "Population"]) writer.writerows(list_of_rows) 最後の行の上に。