2016-07-22 56 views
-1

Pyhton中的數據刮擦。 代碼工作正常,但它顯示了我在下面提到的錯誤。 可能是什麼原因?Python Data Scraping

import urllib2 
from bs4 import BeautifulSoup 
from xlwt import workbook 

wb = Workbook() 
sheet1 = wb.add_sheet('Sheet1') 

soup = BeautifulSoup(urllib2.urlopen("http://en.wikipedia.org/wiki/List_of_Indian_satellites").read()) 

for row in soup('table', {'class': 'wikitable sortable jquery-tablesorter’})[0].tbody('tr'): 
    tds = row('td') 
    sheet1.write(row, 0, tds[0].string) 
    sheet2.write(row, 1, tds[1].string)  

wb.save('Performance Project.xls')  

Error: File "ProcessingProject.py", line 12 SyntaxError: Non-ASCII character '\xe2' in file ProcessingProject.py on line 12

但沒有編碼聲明;見http://python.org/dev/peps/pep-0263/的細節

回答

0
#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

添加到您的文件

0

在湯( '表',{ '類': 'wikitable排序jQuery的的tablesorter'})行的頂部[0] .tbody ('tr'):

您在jquery-tablesorter中使用了錯誤的字符作爲單引號分隔符號