python - 使用 scrapy 链接请求

标签 python web-scraping scrapy

现在我可以看到 scrapy 同时下载所有页面,但我需要的是链接 peopleextract_person 方法,这样当我在方法 people 我关注他们所有人并抓取我需要的所有信息,然后我才继续使用另一个页面 people urls。我该怎么做?

def people(self, response):
    sel = Selector(response)
    urls = sel.xpath(XPATHS.URLS).extract()
    for url in urls:
        yield Request(
            url=BASE_URL+url,
            callback=self.extract_person,
        )

def extract_person(self, response):
    sel = Selector(response)
    name = sel.xpath(XPATHS.NAME).extract()[0]
    person = PersonItem(name=name)
    yield student

最佳答案

您可以控制 priority请求数:

priority (int) – the priority of this request (defaults to 0). The priority is used by the scheduler to define the order used to process requests. Requests with a higher priority value will execute earlier. Negative values are allowed in order to indicate relatively low-priority.

将人员请求的优先级设置为 1 将让 Scrapy 知道首先处理它们:

for url in student_urls:
    yield Request(
        url=BASE_URL+url,
        callback=self.extract_person,
        priority=1
    )

关于python - 使用 scrapy 链接请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26782276/

相关文章:

Python urlopen Windows 身份验证

python - 通过循环和参数组合多个函数

python - heapq.nlargest() 的关键函数

r - 使用 rvest 抓取 - 当标签不存在时使用 NAs 完成

python - 如何从无限滚动网页中抓取正确数量的 URL?

python - 如何在没有回调的情况下从 scrapy.Request 获得响应?

python - PySpark 两个值的总和

php - 从 PHP 页面中抓取 Price Div 类

python - 无法在我的 Windows 10 x64 机器上安装 scrapy

scrapy - yahoo finance 是否禁止 web scrapy?