首页 > 解决方案 > 如何使用“python scrapy.program.py”运行scrapy程序

问题描述

在一个教程中,我找到了这段代码

ietf.py

import scrapy


class IetfSpider(scrapy.Spider):
    name = 'ietf'
    allowed_domains = ['pythonscraping.com']
    start_urls = ['http://pythonscraping.com/linkedin/ietf.html']

    def parse(self, response):
        #title = response.css("span.title::text").get()
        title = response.xpath('//span[@class="title"]text()').get()
        return {"title": title}

我知道如何在 powershell 中使用此命令运行此代码:

scrapy runspider ietf.py

但我想通过使用典型来运行这段代码:

python ietf.py

我需要为程序添加什么代码才能仅使用“python ietf.py”运行它?

标签: pythonscrapy

解决方案


推荐阅读