Learn an extractor
compile_extractorLearn a reusable extractor from a few pages of one template, then replay it on similar pages to extract structured fields and rows automatically.
Instructions
Learn an extractor from pages of one template, to replay later for free.
pages: http(s) URLs, or the HTML itself, of pages built from one template -- two or three pages of one listing, or of one kind of product page. listing: learn the rows the pages repeat; by default only where they declare nothing about a thing. want: example values one row of the listing holds, by the name each column is to have, as {"price": "41.90", "title": "Brake pad set"}: they choose the listing and the columns, and only those columns are kept. A value that no row holds is an error that names it. select: instead of want, each field by a CSS or XPath selector you write, as {"title": "h1", "price": "span.price::text"}; pages may then be empty. Where the fields are is not learnt; what the pages show of them is, and a run fails when a selector finds nothing. Try a selector first with select_values. rows: with select, the selector of a listing's rows ("li.product"), each field then read inside each row.
Returns {"ok", "extractor"}: keep that object and hand it to run_extractor. It holds what the pages declared, the listing's place, its fields, and what every field looked like. An extractor heavier than one answer may be, 75,000 bytes, is too_large: sluicer compile writes it to a file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | with select, the selector of a listing's rows ("li.product"), each field then read inside each row. | |
| want | No | example values one row of the listing holds, by the name each column is to have, as {"price": "41.90", "title": "Brake pad set"}: they choose the listing and the columns, and only those columns are kept. A value that no row holds is an error that names it. | |
| pages | Yes | http(s) URLs, or the HTML itself, of pages built from one template -- two or three pages of one listing, or of one kind of product page. | |
| select | No | instead of want, each field by a CSS or XPath selector you write, as {"title": "h1", "price": "span.price::text"}; pages may then be empty. Where the fields are is not learnt; what the pages show of them is, and a run fails when a selector finds nothing. Try a selector first with select_values. | |
| listing | No | learn the rows the pages repeat; by default only where they declare nothing about a thing. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| error | No | ||
| extractor | No |