我想从这个网站上刮下外汇价格信息,然后把它放到数据库:https://www.mnb.hu/arfolyamok
我写了这个代码,但有点不对劲。我该怎么修,在哪里改? 我正在Windows7上使用Python2.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)
将
# coding=utf-8
添加到代码顶部。这将有助于解决你收到的语法错误。还要确保你的缩进是正确的!你知道吗相关问题 更多 >
编程相关推荐