yinzishao / NewsScrapy

基于scrapy的新闻爬虫
GNU Lesser General Public License v3.0
94 stars 32 forks source link

Python2还是Python3? #14

Open halohsu opened 3 years ago

halohsu commented 3 years ago

Python2还是Python3?

halohsu commented 3 years ago

当我使用Python2运行,会提示导入suppress失败,suppress是Python3的新特性,但是当我使用Python3运行,那么会提示print函数调用错误,因为print函数在Python2和Python3上的语法不一致:

C:\Users\Administrator\NewsScrapy\thepaper>scrapy crawl thepaper -o log/thepaper.json --logfile log/thepaper.log
Traceback (most recent call last):
  File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python39\Scripts\scrapy.exe\__main__.py", line 7, in <module>
  File "c:\program files\python39\lib\site-packages\scrapy\cmdline.py", line 144, in execute
    cmd.crawler_process = CrawlerProcess(settings)
  File "c:\program files\python39\lib\site-packages\scrapy\crawler.py", line 280, in __init__
    super().__init__(settings)
  File "c:\program files\python39\lib\site-packages\scrapy\crawler.py", line 152, in __init__
    self.spider_loader = self._get_spider_loader(settings)
  File "c:\program files\python39\lib\site-packages\scrapy\crawler.py", line 146, in _get_spider_loader
    return loader_cls.from_settings(settings.frozencopy())
  File "c:\program files\python39\lib\site-packages\scrapy\spiderloader.py", line 67, in from_settings
    return cls(settings)
  File "c:\program files\python39\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
    self._load_all_spiders()
  File "c:\program files\python39\lib\site-packages\scrapy\spiderloader.py", line 51, in _load_all_spiders
    for module in walk_modules(name):
  File "c:\program files\python39\lib\site-packages\scrapy\utils\misc.py", line 88, in walk_modules
    submod = import_module(fullpath)
  File "c:\program files\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 851, in exec_module
  File "<frozen importlib._bootstrap_external>", line 988, in get_code
  File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\Administrator\NewsScrapy\thepaper\thepaper\spiders\36kr_spider.py", line 90
    print comment_num
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(comment_num)?