在scrapy項目的spider目錄下,建一個main.py
輸入以下内容
from scrapy.cmdline import execute
execute('scrapy crawl 爬蟲名'.split())
爬蟲檔案中設定斷點,在main.py 點debug 按鈕
20190510添加 (這個也可以的)
from
scrapy.cmdline
import
execute
#調用此函數可以執行scrapy的腳本
import
sys
import
os
# 用來設定工程目錄,有了它才可以讓指令行生效
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
#os.path.abspath(__file__) 用來擷取目前py檔案的路徑
#os.path.dirname() 用來擷取檔案的父親的路徑
#調用execute()函數執行scarpy的指令 scary crawl 爬蟲檔案名字
execute([
'scarpy'
,
'crawl'
,
'jobbole'
])