2016-07-22 72 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中使用了错误的字符作为单引号分隔符号