如何使用scrapy合约? [英] How to work with the scrapy contracts?

查看:32
本文介绍了如何使用scrapy合约?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scrapy Contracts 问题

我开始研究scrapy框架.也实现了一些蜘蛛提取,但我无法为蜘蛛编写单元测试用例,因为合同scrapy 提供的包文档没有正确的程序来编写测试用例.请帮我解决这个问题.

I started working on the scrapy framework. Implemented some spiders too for extraction, but I am not able to write a unit test case for the spider because the contracts package documentation provided by the scrapy doesn't have a proper procedure to write the test cases. Please help me with this thing.

推荐答案

是的,Spiders Contracts 远非清晰和详细.

Yes, Spiders Contracts is far from being clear and detailed.

我不是编写蜘蛛合约的专家(实际上在编写网络抓取教程时只写过一次它们)a> 在 newcoder.io).但是每当我需要为 Scrapy 蜘蛛编写测试时,我更喜欢遵循此处建议的方法 - 从本地 html 文件.如果这仍然是一个单元测试程序,这是有争议的,但这为您提供了更多的灵活性和健壮性.

I'm not an expert in writing spider contracts (actually wrote them only once while working on web-scraping tutorial at newcoder.io). But whenever I needed to write tests for Scrapy spiders, I preferred to follow the approach suggested here - create a fake response from a local html file. It is arguable if this is still a unit testing procedure, but this gives you way more flexibility and robustness.

请注意,您仍然可以编写合同,但您很快就会觉得需要扩展它们并编写自定义合同.没问题.

Note that you can still write contracts but you will quickly feel the need of extending them and writing custom contracts. Which is pretty much ok.

相关链接:

这篇关于如何使用scrapy合约?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆