scrapy 单文件启动单个spider

 

 

 

import scrapy
from scrapy.crawler import CrawlerRunner
from scrapy.settings import Settings
from twisted.internet import reactor


class ExampleSpider(scrapy.Spider):
    name = 'example'
    allowed_domains = ['example.com']
    start_urls = ['']

    def parse(self, response):
        print(response.text)


settings = Settings({'USER_AGENT': 'PYTHON'})
runner = CrawlerRunner(settings)
d = runner.crawl(ExampleSpider)
d.addBoth(lambda _: reactor.stop())
reactor.run()

 

posted @ 2024-06-19 12:18  AngDH  阅读(14)  评论(0编辑  收藏  举报