Python网络刮擦交易价格



我想从本网站上删除交易价格信息,然后将其带入数据库: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)

# coding=utf-8添加到代码顶部。这将有助于解决您收到的语法。还要确保您的凹痕正确!

相关内容

最新更新