2017-06-07 63 views
0

我想從這個網站刮交換價格信息,並採取後入數據庫:https://www.mnb.hu/arfolyamokPython網絡交流刮價格

我寫了這個代碼,但蹊蹺的吧。我如何解決它,我必須改變它? 我與Python 2.7.13在Windows 7

的代碼工作是在這裏:

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

你面臨的實際問題是什麼? –

+0

這是你得到的錯誤? 'SyntaxError:第24行文件scrapetest.py中的非ASCII字符'\ xc3',但未聲明編碼;詳情請參閱http://python.org/dev/peps/pep-0263/ – cosinepenguin

+1

我們**不是**代碼編寫服務,這裏的一個問題應該有一個明確的問題,應該列出你試圖解決的問題你的問題,它應該包括任何可能幫助我們找出問題的信息。你說'有什麼問題',但是你不能指出它出了什麼問題。我們需要知道你的預期結果,以及你實際得到的結果。請回顧[如何提出一個好問題](https://stackoverflow.com/help/how-to-ask) – GrumpyCrouton

回答

1

添加# coding=utf-8到代碼的頂部。這將有助於解決您收到的SyntaxError錯誤。還要確保你的縮進是正確的!