Python Scrapy不断回归;无效语法";

Python Scrapy不断回归;无效语法";,python,scrapy,Python,Scrapy,我对刮痧很陌生,今天是我第一天看它。我遇到了最基本的代码问题。我一直收到一个错误,说无效语法。这是我的代码,下面是我得到的错误。我在终端上运行这个,而不是python本身 # -*- coding: utf-8 -*- import scrapy class QuotesSpider(scrapy.Spider): name = 'quotes' allowed_domains = ['toscrape.com'] start_urls = ['http://tosc

我对刮痧很陌生,今天是我第一天看它。我遇到了最基本的代码问题。我一直收到一个错误,说
无效语法
。这是我的代码,下面是我得到的错误。我在终端上运行这个,而不是python本身

# -*- coding: utf-8 -*-
import scrapy


class QuotesSpider(scrapy.Spider):
    name = 'quotes'
    allowed_domains = ['toscrape.com']
    start_urls = ['http://toscrape.com/random']

    def parse(self, response):
        print(response.url)

2018-09-11 18:30:29 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: scrapybot)
2018-09-11 18:30:29 [scrapy.utils.log] INFO: Versions: lxml 4.2.5.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.5.0, w3lib 1.19.0, Twisted 18.7.0, Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) - [Clang 6.0 (clang-600.0.57)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0i  14 Aug 2018), cryptography 2.3.1, Platform Darwin-17.7.0-x86_64-i386-64bit
2018-09-11 18:30:29 [scrapy.crawler] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/scrapy", line 11, in <module>
    sys.exit(execute())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/cmdline.py", line 150, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/cmdline.py", line 90, in _run_print_help
    func(*a, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/cmdline.py", line 157, in _run_command
    cmd.run(args, opts)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/commands/runspider.py", line 88, in run
    self.crawler_process.crawl(spidercls, **opts.spargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/crawler.py", line 170, in crawl
    crawler = self.create_crawler(crawler_or_spidercls)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/crawler.py", line 198, in create_crawler
    return self._create_crawler(crawler_or_spidercls)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/crawler.py", line 203, in _create_crawler
    return Crawler(spidercls, self.settings)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/crawler.py", line 55, in __init__
    self.extensions = ExtensionManager.from_crawler(self)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/middleware.py", line 58, in from_crawler
    return cls.from_settings(crawler.settings, crawler)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/middleware.py", line 34, in from_settings
    mwcls = load_object(clspath)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/utils/misc.py", line 44, in load_object
    mod = import_module(module)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/extensions/telnet.py", line 12, in <module>
    from twisted.conch import manhole, telnet
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/conch/manhole.py", line 154
    def write(self, data, async=False):
                              ^
SyntaxError: invalid syntax
#-*-编码:utf-8-*-
进口羊瘙痒
类QuotesSpider(刮毛蜘蛛):
名称='quotes'
允许的_域=['toscrape.com']
起始URL=['http://toscrape.com/random']
def解析(自我,响应):
打印(response.url)
2018-09-11 18:30:29[scrapy.utils.log]信息:scrapy 1.5.1已启动(bot:scrapybot)
2018-09-11 18:30:29[scrapy.utils.log]信息:版本:lxml 4.2.5.0,libxml2.9.8,CSSELECT 1.0.3,parsel 1.5.0,w3lib 1.19.0,Twisted 18.7.0,Python 3.7.0(v3.7.0:1bf9cc5093,2018年6月26日,23:26:24)-[Clang 6.0(Clang-600.0.0.0.0.0.0)],pyOpenSSL 18.0.0(OpenSSL 1.1.0.0.0i 2018年8月14日),cryptography 2.3.1,cryptography 2.1,Darwin-x86-I646位平台
2018-09-11 18:30:29[scrapy.crawler]信息:覆盖的设置:{'SPIDER_LOADER_WARN_ONLY':True}
回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.7/bin/scrapy”,第11行,在
sys.exit(execute())
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/cmdline.py”,执行中的第150行
_运行\u打印\u帮助(解析器、\u运行\u命令、cmd、args、opts)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/cmdline.py”,第90行,在“运行”和“打印”帮助中
func(*a,**千瓦)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/cmdline.py”,第157行,在_run_命令中
cmd.run(参数、选项)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scrapy/commands/runspider.py”,第88行,运行中
self.crawler\u process.crawl(spidercls,**opts.spargs)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/crawler.py”,第170行,在爬网中
爬虫=自我。创建爬虫(爬虫或蜘蛛)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/crawler.py”,第198行,在create_crawler中
返回自我。创建爬虫程序(爬虫程序或蜘蛛程序)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/crawler.py”,第203行,在创建爬虫程序中
返回爬虫程序(spidercls、self.settings)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/crawler.py”,第55行,在__
self.extensions=ExtensionManager.from_crawler(self)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/middleware.py”,第58行,来自爬虫程序
返回cls.from_设置(crawler.settings,crawler)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/middleware.py”,第34行,在from_设置中
mwcls=加载对象(clspath)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/utils/misc.py”,第44行,在load_对象中
mod=导入模块(模块)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/\uuuu init\uuuuu.py”,第127行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第1006行,在\u gcd\u导入中
文件“”,第983行,在_find_和_load中
文件“”,第967行,在“查找”和“加载”中解锁
文件“”,第677行,在\u加载\u解锁
exec_模块中第728行的文件“”
文件“”,第219行,在“调用”中,删除了“帧”
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/scrapy/extensions/telnet.py”,第12行,在
从twisted.conch导入人孔,telnet
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/conch/shall.py”,第154行
def写入(自、数据、异步=False):
^
SyntaxError:无效语法

异步是Python>3.4的一个关键字。
您必须检查您的python版本,并且该库支持您的python版本

检查过了,我正在运行python3.7我想它可能适合你;使用_async作为变量名,而不是async(shanny.py,第154行),我使用了isAsync。也许可以检查一下:@JoeA将我带到Github,但那里什么都没有?应该是这样的链接:@JoeA您已经得到了答案。将其作为答案发布,我将对其进行升级。似乎您需要安装3.6版或编辑a文件。