python - Scrapy make_requests_from_url(url)

标签 python web-crawler scrapy

Scrapy教程中有BaseSpider的这个方法:

make_requests_from_url(url)

A method that receives a URL and returns a Request object (or a list of Request objects) to scrape.

This method is used to construct the initial requests in the start_requests() method, and is typically used to convert urls to requests.

Unless overridden, this method returns Requests with the parse() method as their callback function, and with dont_filter parameter enabled (see Request class for more info).

你明白这个方法的作用吗?我可以使用 makerequestsfrom_url 和 BaseSpider 来代替不适合我的 SgmlLinkExtractor 和 CrawlSpider 吗?

我正在尝试抓取超出给定初始网址的内容,而 Scrapy 没有这样做。

谢谢

最佳答案

没错,CrawlSpider在许多情况下很有用且方便,但它仅涵盖所有可能的蜘蛛的子集。如果您需要更复杂的东西,您通常会子类 BaseSpider并实现start_requests()方法。

关于python - Scrapy make_requests_from_url(url),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1810143/

相关文章:

python - Scrapy & 验证码

python - 我如何使用Django查询集过滤器创建views.py来比较django中两个不同表的特定值?

Python 与 Keras 数据集错误, "X is not defined"

python - Scrapy 只抓取网站的一部分

python - 返回 self._values[key] 异常.KeyError : Python

python - 在 PyParsing 中,如何指定一个 Word 不等于给定的文字?

python - 如何计算从期初开始的累计百分比变化

python - 在Python中创建一个与目录同名的文件

python - Scrapy 和 Django 导入报错

seo - 如何防止谷歌机器人抓取页面的特定部分?