I'm trying to scrape this html table with BeautifulSoup on Python 3.6 in order to export it to csv, as in the scripts below. I used a former example, trying to fit my case.
url = 'http://finanzalocale.interno.it/apps/floc.php/certificati/index/codice_ente/2050540010/cod/4/anno/2015/md/0/cod_modello/CCOU/tipo_modello/U/cod_quadro/03'
html =urlopen(url).read
soup = BeautifulSoup(html(), "lxml")
table = soup.select_one("table.tabfin")
headers = [th.text("iso-8859-1") for th in table.select("tr th")]
but I receive an AttributeError.
AttributeError: 'NoneType' object has no attribute 'select'
Then I would try to export to csv with
with open("abano_spese.csv", "w") as f:
wr = csv.writer(f)
wr.writerow(headers)
wr.writerows([[td.text.encode("iso-8859-1") for td in row.find_all("td")] for row in table.select("tr + tr")])
What's wrong with this? I'm sorry if there's some stupid error, I'm an absolute beginner with python.
Thank you all