python - 如何分析一个scrapy python脚本?

标签 python scrapy profiling scrapy-spider

以示例脚本为例

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class MySpider(CrawlSpider):
    name = 'example.com'
    allowed_domains = ['example.com']
    start_urls = ['http://www.example.com']

    rules = (
        # Extract links matching 'category.php' (but not matching 'subsection.php')
        # and follow links from them (since no callback means follow=True by default).
        Rule(LinkExtractor(allow=('category\.php', ), deny=('subsection\.php', ))),

        # Extract links matching 'item.php' and parse them with the spider's method parse_item
        Rule(LinkExtractor(allow=('item\.php', )), callback='parse_item'),
    )

    def parse_item(self, response):
        self.logger.info('Hi, this is an item page! %s', response.url)
        item = scrapy.Item()
        item['id'] = response.xpath('//td[@id="item_id"]/text()').re(r'ID: (\d+)')
        item['name'] = response.xpath('//td[@id="item_name"]/text()').extract()
        item['description'] = response.xpath('//td[@id="item_description"]/text()').extract()
        return item

任何人都可以让我知道如何对这个脚本进行分析吗?

谢谢

最佳答案

这取决于您要配置文件的内容:

  • 如果是一般调试,见Debugging Spiders
  • 如果是内存占用,见Debugging memory leaks
  • 如果是爬取率等统计,见Stats Collection
  • 如果你想在运行时与蜘蛛交互,Telnet Console可能是要走的路。

  • 还有Logging , 当然。

    关于python - 如何分析一个scrapy python脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46865284/

    相关文章:

    python - Python中的二分搜索(二分法)

    python - 在使用 pyinstaller 制作的可执行文件中获取运行时错误

    python - 使用Scrapy解析站点,跟随Next Page,写成XML

    python - 有没有办法减少 Scrapy 的内存消耗?

    macos - 在没有仪器的 OS X 上记录性能监视器计数器(PM 事件)的值

    python - 复制列表错误Python(康威生命游戏的一部分)

    python - Django : Iterate over a query set without cache

    java - 从本地触发远程服务器上的快照

    javascript - Scrapy 选择器无法返回所需的字符,可能是由于 Javascript

    c# - 通过 Visual Studio 性能分析,应用程序运行速度更快