python - 在哪里可以了解 scrapy SgmlLinkExtractor?

标签 python scrapy

抱歉,我对 python 和 scrapy 非常陌生,试图通过反复试验来学习它们。

关于SgmlLinkExtractor,我看到每个人(至少在这个网站上)都非常擅长找到正确的代码来表示正确的路径,我在哪里/如何学习? 例如 (allow=[r'page/\d+'])allow=[r'series-\d{1}-episode-\d{2}.']等等等等

我正在尝试删除一个网站,其内容始终为story.html,链接格式如下:

http://www.example.com/folder/category/description/1234567/story.html

*注1234567是一个变化的7位数字

我的起始网址是 http://www.example.com/folder/

我正在尝试使用 SgmlLinkExtractor 并定义我的路径,如下所示。我想包含 url 的描述部分和 7 位数字部分中的所有内容。我想确保网址以 story.html 结尾:

Rule(SgmlLinkExtractor(allow=(r'category1/././story\.html',)),callback='parse_item', follow=True),

但显然/././不允许我跳过两个子级别来到达story.html

编写此 SgmlLinkExtractor 的正确方法是什么?

最佳答案

试试这个

Rule(SgmlLinkExtractor(allow=(r'category1/description/\d+/story\.html',)), callback='parse_item', follow=True)

但我建议您仅使用 /description/\d+/story\.html 这部分,因为它的独特性足以抓取类别

在规则中我们传递正则表达式,所以你只需要学习 regex ,有一堆online regex tester工具可用

关于python - 在哪里可以了解 scrapy SgmlLinkExtractor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15651417/

相关文章:

python - 如何从 html 源代码中具有相同属性集和相同层次结构的 2 个元素中抓取单个元素(使用 python 的漂亮汤)

javascript - Lua、Scrapy/Splash : Clicking button with no href

python - 规范化空间不足以呈现糟糕的内容

python pandas - 用字符串替换数字

python - Scrapy 返回 403 错误(禁止)

python - 如何在Python中找到素数函数

python - python3 中的原始套接字

python - Scrapy:scrapy server需要一个项目,为什么?

python - 从给定字符串中删除\n 或\t

python - 保存为 tensorflow 图的 Keras 顺序模型缺少火车操作?