python - Scrapy 关注并抓取下一页

标签 python python-2.7 web-scraping scrapy

我遇到一个问题,我的 scrapy 蜘蛛都不会抓取网站,只是抓取一页并抓取。我的印象是 rules 成员变量对此负责,但我无法让它跟踪任何链接。我一直在关注这里的文档:http://doc.scrapy.org/en/latest/topics/spiders.html#crawlspider

我可能遗漏了什么,导致我的机器人无法爬行?

from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
from scrapy.selector import Selector

from Example.items import ExItem

class ExampleSpider(CrawlSpider):
    name = "example"
    allowed_domains = ["example.ac.uk"]
    start_urls = (
        'http://www.example.ac.uk',
    )

    rules = ( Rule (LinkExtractor(allow=("", ),),
                    callback="parse_items",  follow= True),
    )

最佳答案

将您的规则替换为以下规则:

rules = ( Rule(LinkExtractor(allow=('course-finder', ),restrict_xpaths=('//div[@class="pagination"]',)), callback='parse_items',follow=True), )

关于python - Scrapy 关注并抓取下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28805663/

相关文章:

python - 当增加迭代次数时,多进程会变成僵尸进程。 mp.Queue() 与 Manager.list() 相比有何优势?

python - 使用 Python (BeautifulSoup 4) 的网络抓取工具不起作用

python - 网站上的选项卡是 "Not Clickable"使用 Selenium 和/Python

python - Stacked DenoisingAutoencoders 的 Theano 实现 - 为什么 dA 层的输入相同?

python - 如何使用 pandas 快速将数据框中的字符串更改为整数 ID?

class - 将特定的东西分配给 Python 中的类

python - 尝试抓取任何地方或餐厅的谷歌首页地址,但不幸的是

python - 在 pypi python setup.py 中指定可选依赖项

python - Python 3.4 Docker 容器中的 AWS Elastic Beanstalk 容器命令

python - 尝试通过python创建快捷方式