tardos93
tardos93

Reputation: 233

Python web scraping exchange prices

I want scraping the exchange prices informations from this website and after take it into a database: https://www.mnb.hu/arfolyamok

I wrote this code, but something wrong with it. How can i fix it, where i have to change it? I am working with Python 2.7.13 on Windows 7.

The code is here:

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)

Upvotes: 0

Views: 99

Answers (1)

cosinepenguin
cosinepenguin

Reputation: 1575

Add # coding=utf-8 to the top of your code. This will help solve the SyntaxError you are receiving. Also make sure your indentation is correct!

Upvotes: 1

Related Questions