HTML Parser
The HTML Parser cuts the part you want out of a page with simple text commands. Use it when automatic extraction picks the wrong part, or when you need several pieces of a page put together.
Input and output
- Input:
url(the page is downloaded) orhtml, chosen with Input. - Output:
html(the result of the last command) andfull_html(the whole page).
Options
- Input: URL or HTML.
- Code: the commands, one per line.
- Syntax Separator: the character between the parts of a command. Default
|. - get CURL: Level 1 or Level 2.
- Clear Tags: tags removed first, with their content. Default
script,style,head. - Entities: convert special characters to HTML entities and back, for pages with broken characters.
- Clear Space: remove extra white space.
Commands
The page is row 0. Every command works on a row and adds its result as the next row (1, 2, 3, ...). The last row is the output.
| Command | Form | What it does |
|---|---|---|
ginner |
ginner\|row\|tag\|attribute |
The inside of the first tag that has attribute. Add \|1 for the second match, \|L for the last |
remove |
remove\|row\|tag\|attribute |
The row without that tag and its content |
split |
split\|row\|text\|part |
Split the row at text and keep part number part (from 0, or L for the last) |
replace |
replace\|row\|find\|replace |
Replace text |
wrap |
wrap\|row,row\|template |
Put rows into a template, where {ogb-0} is the first row given and {ogb-1} the second |
If a command fails, the item is stopped with an error such as "Error row-2".
Example
ginner|0|div|class="article-body"
remove|1|div|class="share-buttons"
replace|2|Read more on our site|
- Row 1: the content of
<div class="article-body">. - Row 2: row 1 without the share buttons.
- Row 3: row 2 without the "Read more" text. This is the output.
Another example that keeps what comes after a heading:
split|0|<h1 class="title">|1
split|1|<div class="comments">|0
Tips
- Copy the tag and attribute exactly as they are in the page source (View Page Source in the browser), quotes included.
- The same commands work in the Parser Code option of Get Fulltext.
- For pages where an XPath query is easier, use Get XPath Content.