scrapy出现OSError: could not get source code错误解决

avatar
作者
筋斗云
阅读量:0

出现问题如下:

Traceback (most recent call last):   File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\defer.py", line 73, in mustbe_deferred     result = f(*args, **kw)   File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\core\spidermw.py", line 92, in _process_spider_input     return scrape_func(response, request, spider)   File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\core\scraper.py", line 200, in call_spider     warn_on_generator_with_return_value(spider, callback)   File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\misc.py", line 258, in warn_on_generator_with_return_value     if is_generator_with_return_value(callable):   File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\misc.py", line 234, in is_generator_with_return_value     src = inspect.getsource(func)   File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1139, in getsource     lines, lnum = getsourcelines(object)   File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1121, in getsourcelines     lines, lnum = findsource(object)   File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 958, in findsource     raise OSError('could not get source code') OSError: could not get source code  

原因:想必是你小子手动创建了爬虫文件,这样出现了编码问题

解决办法:爬虫文件添加编码头注释 #coding=utf8

#coding=utf8 import scrapy 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!