安裝的是Python3.7,裝上依賴包和scrapy后運行爬蟲命令出錯
1 File "D:\Python37\lib\site-packages\scrapy\extensions\telnet.py", line 12, in <module> 2 from twisted.conch import manhole, telnet 3 File "D:\Python37\lib\site-packages\twisted\conch\manhole.py", line 154 4 def write(self, data, async=False): 5 ^ 6 SyntaxError: invalid syntax 7 8 Process finished with exit code 1
解決方法:
1 def write(self, data, shark=False): 2 self.handler.addOutput(data, shark) 3 4 def addOutput(self, data, shark=False): 5 if shark: 6 self.terminal.eraseLine() 7 self.terminal.cursorBackward(len(self.lineBuffer) + len(self.ps[self.pn])) 8 9 self.terminal.write(data) 10 11 if shark: 12 if self._needsNewline(): 13 self.terminal.nextLine() 14 15 self.terminal.write(self.ps[self.pn])
將源碼manhole.py中的async參數更改為shark(注意更換全部)
可以直接點擊錯誤跳轉
也可以通過文件路徑查找
D:\Python37\Lib\site-packages\twisted\conch\manhole.py
改完再運行就OK了