方法一:使用以下脚本形式运行命令报错 from scrapy import cmdline cmdline.execute(['scrapy', 'crawl', 'spidername'])
#子文件夹
import scrapy
class GswwSpiderSpider(scrapy.Spider):
name = 'gsww_spider'
allowed_domains = ['gushiwen.org']
start_urls = ['https://www.gushiwen.org/default_1.aspx']
def myprint(self, value):
print("=" * 30)
print(value)
print("=" * 30)
def parse(self, response):
self.myprint(type(response))
#根目录下
from scrapy import cmdline
import os
# "scrapy crawl gsww_spider".split(" ")
cmds = ['scrapy','crawl','gsww_spider']
cmdline.execute(cmds)
方法二:cmd通过 python myspider.py 可以执行该文件未报错