1.这里采用run.py脚本方式
1 # 通过CrawlerProcess同时运行几个spider 2 import scrapy 3 from scrapy.crawler import CrawlerProcess 4 from scrapy.utils.project import get_project_settings 5 from spiders.test import TestSpider 6 7 name = '小明' 8 process = CrawlerProcess(get_project_settings()) 9 process.crawl(TestSpider,name) # 注意引入 10 process.start()
2.修改spider的初始化函数test.py
class TestSpider(scrapy.Spider): def __init__(self,name): self.urls ='https://www.xxxxxx.com/actor=%s&page=1'%(name)
3.运行可得self.urls的值为: