问题描述
在scrapy的爬虫文件中出现了这样的错误:SyntaxError
文件树
出错的文件
itcast2.py
import scrapy
"""logging模块的使用"""
import logging
class Itcast2Spider(scrapy
.Spider
):
name
= 'itcast2'
allowed_domains
= ['itcast.cn']
start_urls
= ['http://www.itcast.cn/channel/teacher.shtml#ajavaee']
def parse(self
, response
):
for i
in range(10):
item
={}
item
["come_from"]=self
.name
logging
.warning
(item
)
问题分析
出错的地方
Myspider\Myspider\spiders\itcast2.py", line 2
出错分析
注意:在scrapy框架的爬虫文件中,不能够像下面一样
会报什么错误
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xbf in position 9: invalid start byte
问题解决
很简单,在文件的最上面加一行这样的代码: # -*- coding: utf-8 -*-
再次运行
问题完美解决