Ich habe ein Web-Scraping, und ich bekomme eine Tabelle, die ich in CSV schreiben möchte.Python Web-Scraping in CSV
Wenn ich es versuche, bekomme ich diese Meldung:
"Traceback (most recent call last):
File "C:/Python27/megoldas3.py", line 27, in <module>
file.write(bytes(header,encoding="ascii",errors="ignore")) TypeError:
str() takes at most 1 argument (3 given)"
Was ist mit diesem Code falsch? Ich benutze Python 2.7.13.
import urllib2
from bs4 import BeautifulSoup
import csv
import os
out=open("proba.csv","rb")
data=csv.reader(out)
def make_soup(url):
thepage = urllib2.urlopen(url)
soupdata = BeautifulSoup(thepage, "html.parser")
return soupdata
maindatatable=""
soup = make_soup("https://www.mnb.hu/arfolyamok")
for record in soup.findAll('tr'):
datatable=""
for data in record.findAll('td'):
datatable=datatable+","+data.text
maindatatable = maindatatable + "\n" + datatable[1:]
header = "Penznem,Devizanev,Egyseg,Penznemforintban"
print maindatatable
file = open(os.path.expanduser("proba.csv"),"wb")
file.write(bytes(header,encoding="ascii",errors="ignore"))
file.write(bytes(maindatatable,encoding="ascii",errors="ignore"))
'bytes' nur einen Parameter nehmen – Arun
ich die Fehlermeldung zu verstehen, aber ich weiß nicht, wie ich es zu korrigieren. – tardos93
'encoding =" ascii ", errors =" ignore "' sind die Attribute, wenn Schreibfunktion nicht von Bytes, habe ich die Antwort unter – Arun