您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關如何解決Scrapy啟動報錯invalid syntax的問題,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
Traceback (most recent call last): File “d:\python\lib\runpy.py”,
line 193, in _run_module_as_main
“main”, mod_spec) File “d:\python\lib\runpy.py”, line 85, in run_code
exec(code, run_globals) File "D:\python\Scripts\scrapy.exe_main.py", line 9, in File
“d:\python\lib\site-packages\scrapy\cmdline.py”, line 150, in execute
_run_print_help(parser, _run_command, cmd, args, opts) File “d:\python\lib\site-packages\scrapy\cmdline.py”, line 90, in
_run_print_help
func(*a, **kw) File “d:\python\lib\site-packages\scrapy\cmdline.py”, line 157, in
_run_command
cmd.run(args, opts) File “d:\python\lib\site-packages\scrapy\commands\crawl.py”, line 57, in
run
self.crawler_process.crawl(spname, **opts.spargs) File “d:\python\lib\site-packages\scrapy\crawler.py”, line 170, in crawl
crawler = self.create_crawler(crawler_or_spidercls) File “d:\python\lib\site-packages\scrapy\crawler.py”, line 198, in
create_crawler
return self._create_crawler(crawler_or_spidercls) File “d:\python\lib\site-packages\scrapy\crawler.py”, line 203, in
create_crawler
return Crawler(spidercls, self.settings) File “d:\python\lib\site-packages\scrapy\crawler.py”, line 55, in init
self.extensions = ExtensionManager.from_crawler(self) File “d:\python\lib\site-packages\scrapy\middleware.py”, line 58, in
from_crawler
return cls.from_settings(crawler.settings, crawler) File “d:\python\lib\site-packages\scrapy\middleware.py”, line 34, in
from_settings
mwcls = load_object(clspath) File “d:\python\lib\site-packages\scrapy\utils\misc.py”, line 44, in
load_object
mod = import_module(module) File "d:\python\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File “
啟動命令如下:
scrapy crawl first_spider -o first_spider.csv
經過查詢發現async在python3.7中是保留字,因此將twisted\conch\manhole.py中的async修改為isasync即可解決問題
使用xpath和CSS遇到的一些 invalid syntax
錯誤:
正確:把定位的xpath外加單引號
錯誤:
正確:注意關鍵字不能做變量
錯誤:
正確:去掉url的引號
錯誤:因為一開始網址就是錯誤的,所以不管匹配的xpath是不是對的,都會返回【】
正確:
看完上述內容,你們對如何解決Scrapy啟動報錯invalid syntax的問題有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。