我想从这个网站上抓取交换价格信息,然后将其带入数据库:https://www.mnb.hu/arfolyamok
我写了这段代码,但是它有些不对劲。我怎么能解决它,我必须改变它? 我在Windows 7上使用Python 2.7.13。
代码在这里:
import csv
import requests
from BeautifulSoup import BeautifulSoup
url = 'https://www.mnb.hu/arfolyamok'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html)
table = soup.find('tbody', attrs={'class': 'stripe'})
list_of_rows = []
for row in table.findAll('tr')[1:]:
list_of_cells = []
for cell in row.findAll('td'):
text = cell.text.replace(' ', '')
list_of_cells.append(text)
list_of_rows.append(list_of_cells)
print list_of_rows
outfile = open("./inmates.csv", "wb")
writer = csv.writer(outfile)
writer.writerow(["Pénznem", "Devizanév", "Egység", "Forintban kifejezett érték"])
writer.writerows(list_of_rows)
答案 0 :(得分:1)
将# coding=utf-8
添加到代码顶部。这将有助于解决您收到的SyntaxError。还要确保你的缩进是正确的!