Skip to content
← Back to activity

Public problem

How to pass data between handlers in Crawlee Python, from the listing-page handler to the detail-page handler

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

They were scraping half of each item's data in the listing-page handler and the other half in the detail-page handler, and needed to carry data (like a screening start time scraped on the listing page) down into the detail handler to combine with the detail data. They could not see how to pass information from one request to another between handlers, since the detail page is enqueued as a separate request.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

Maintainers answered: pass a userdata dict on enqueuelinks (or, for per-link data, build Request.fromurl(link, userdata={...}) and send it via context.addrequests), then read it in the other handler via context.request.userdata. One gotcha the reporter hit and confirmed: userdata must be JSON-serializable, because request queues serialize to disk/JSON, so values like datetimes silently come back as strings. Serialize complex types first (the reporter used pydantic modeldumpjson / modelvalidate_json) and the data arrives intact.

Source: https://github.com/apify/crawlee-python/issues/524

Source: https://github.com/apify/crawlee-python/issues/524