2015-09-04 158 views
0

我只是遵循了Scrapy文檔,寫下了我的第一隻蜘蛛。(Scrapy)SyntaxError:無效的語法

dmoz_spider.py:

import scrapy 
class DmozSpider(scrapy.Spider): 
    name = "dmoz" 
    allowed_domains = ["dmoz.org"] 
    start_urls = [ 
     "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/", 
     "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/" 
    ] 
    def parse(self, response): 
     filename = response.url.split("/")[-2] + '.html' 
     with open(filename, 'wb') as f: 
      f.write(response.body) 

然後當我運行它,我得到了下面的錯誤。

E:\python2.7-64bit\Lib\site-packages\scrapy\tutorial>scrapy crawl dmoz 
Traceback (most recent call last): 
File "E:\python2.7-64bit\lib\runpy.py", line 162, in _run_module_as_main 
"__main__", fname, loader, pkg_name) 
File "E:\python2.7-64bit\lib\runpy.py", line 72, in _run_code 
exec code in run_globals 
File "E:\python2.7-64bit\Scripts\scrapy.exe\__main__.py", line 9, in <module> 
File "E:\python2.7-64bit\lib\site-packages\scrapy\cmdline.py", line 142, in execute 
cmd.crawler_process = CrawlerProcess(settings) 
File "E:\python2.7-64bit\lib\site-packages\scrapy\crawler.py", line 209, in __init__ 
super(CrawlerProcess, self).__init__(settings) 
File "E:\python2.7-64bit\lib\site-packages\scrapy\crawler.py", line 115, in __init__ 
self.spider_loader = _get_spider_loader(settings) 
File "E:\python2.7-64bit\lib\site-packages\scrapy\crawler.py", line 296, in _get_spider_loader 
return loader_cls.from_settings(settings.frozencopy()) 
File "E:\python2.7-64bit\lib\site-packages\scrapy\spiderloader.py", line 30, in from_settings 
return cls(settings) 
File "E:\python2.7-64bit\lib\site-packages\scrapy\spiderloader.py", line 21, in __init__ 
for module in walk_modules(name): 
File "E:\python2.7-64bit\lib\site-packages\scrapy\utils\misc.py", line 71, in walk_modules 
submod = import_module(fullpath) 
File "E:\python2.7-64bit\lib\importlib\__init__.py", line 37, in import_module 
__import__(name) 
File "E:\python2.7-64bit\Lib\site-packages\scrapy\tutorial\tutorial\spiders\dmoz_spider.py", line 1 
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32 

SyntaxError: invalid syntax 

我怎樣才能解決呢?在Python 2.7-32bit上運行它?

回答

1

你的文件開始使用該文本行:

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32 

刪除了這一行。

相關問題