Context provides a tiny layer for passing data between callbacks.
For example, the Crawler.onHTML callback function puts data into the context.
c.onHTML("a[href]", (e) => { // ... e.request.ctx.put("page_href", e.request.url); e.request.ctx.put("link_text", e.text); //... Copy
c.onHTML("a[href]", (e) => { // ... e.request.ctx.put("page_href", e.request.url); e.request.ctx.put("link_text", e.text); //...
The Crawler.onResponse callback function reads the data previously put by the Crawler.onHTML callback from the context.
c.onResponse((r) => { const page_href = r.request.ctx.get("page_href"); // ... Copy
c.onResponse((r) => { const page_href = r.request.ctx.get("page_href"); // ...
Retrieves a string value from Context. Get returns an empty string if key not found.
key to get
Retrieves a value from Context. GetAny returns null if key not found.
Stores a value of any type in Context.
key to store
value to store
Context provides a tiny layer for passing data between callbacks.
For example, the Crawler.onHTML callback function puts data into the context.
The Crawler.onResponse callback function reads the data previously put by the Crawler.onHTML callback from the context.