HTMLParser Function

Number of input and output field

Number of input field : One
Number of output field : One


HTMLParser is used to scrape data from an HTML document. The scraping result is stored in a single output field. Multiple values (columns) are separated by a tab (\t), and multiple rows are separated by a newline (\n).

The parameters of HTMLParser are: Output
About HTML Components

Using CSS Selectors

DescriptionCSS Selector
Selecting HTML tag (p) name having specified class name (intro)p.intro
Selecting HTML tag having specified id or all div tags with id = "greeting"div#greeting
Selecting element with id greeting#greeting
Selecting element with class name = list mobiles.list.mobiles
Selecting HTML elements having src attribute[src]
Selecting all div having id attributediv[id]
Selecting HTML elements having attribute name starting with data-[^data-]
Selecting HTML elements having specific attribute value[data-index=2]
Selecting HTML elements having data-location attribute value starting with wiki[data-location^=wiki]
Selecting HTML elements having class attribute value ending with tro[class$=tro]
Selecting HTML elements having id attribute value containing eeti[id*=eeti]
Selecting HTML elements having data-name attribute value matching regex[data-name~=.*sung$]
Selecting all child li elements of ul having class name languagesul.languages li
Selecting all child tr elements of table having class name 'tablesorter full'table.tablesorter.full tr
Selecting the first td element td:nth-of-type(1)
Selecting all link (a elements) containing imagesa:has(img)
Selecting div elements without having id attributediv:not([id])
Selecting all ul elements not having class "list languages"ul:not([class=list languages])
Selecting all ul elements having text nokiaul:contains(nokia)
Selecting all div elements having text readdiv:contains(read)
Selecting all ul elements with text matching
with regex pattern "C[+]?" (Character C followed by zero or more + sign)
Elements uls = document.select("ul:matches(C[+]?)")
ul:matches(C[+]?)


Example of using CSS Selectors

  1. A piece of html sample Data :
    ............
    <table class="tablesorter full" id="summary-table">
    	<thead>
    		<tr class="tall">
    			<th><p>Epic</p></th>
    			<th><p>Name</p></th>
    			<th class="right"><p>Price (p)</p></th>
    			<th class="right"><p>Change</p></th>
    			<th class="right"><p>%<br/>Change</p></th>
    			<th class="right"><p>30 day<br/>%</p></th>
    			<th class="right"><p>Market<br/>Cap (m)</p></th>
    			<th class="right"><p> </p></th>
    		</tr>
    	</thead>
    	<tbody>
    						<tr class="odd">
    			<td><a href="/web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=3IN">3IN</a></td>
    			<td><a href="/web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=3IN">3i Infrastructure</a></td>
    			<td class="right">258.88</td>
    			<td class="right change-up">0.53</td>
    			<td class="right change-up">0.21</td>
    			<td class="right change-up">0.73</td>
    			<td class="right">2,103.48</td>
    			<td class="right"><a href="https://web.archive.org/web/20190104110157/https://investor.telegraph.co.uk/papi/v1/services/r/type/3/a/trading-trade/code/LSE:3IN/instruction/B/?WT.mc_id=shares_st_indicesc_20141112&utm_source=shares&utm_medium=st&utm_content=indicesc&utm_campaign=shares_st_indicesc_20141112">Trade now</a></td>
    		</tr>
    								<tr class="even">
    			<td><a href="/web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=888">888</a></td>
    			<td><a href="/web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=888">888 Holdings</a></td>
    			<td class="right">164.45</td>
    			<td class="right change-up">1.85</td>
    			<td class="right change-up">1.14</td>
    			<td class="right change-down">-0.87</td>
    			<td class="right">607.26</td>
    			<td class="right"><a href="https://web.archive.org/web/20190104110157/https://investor.telegraph.co.uk/papi/v1/services/r/type/3/a/trading-trade/code/LSE:888/instruction/B/?WT.mc_id=shares_st_indicesc_20141112&utm_source=shares&utm_medium=st&utm_content=indicesc&utm_campaign=shares_st_indicesc_20141112">Trade now</a></td>
    		</tr>  
    ............
                   

  2. Parameter of Html Source :
    • List of Selector :
      CSS Selector -> table.tablesorter.full tr
      CSS Selector -> td:nth-of-type(1) a,td:nth-of-type(2),td:nth-of-type(3),td:nth-of-type(4),td:nth-of-type(5),td:nth-of-type(6),td:nth-of-type(7),td:nth-of-type(8)
    • Retrieved Value : A,T,T,T,T,T,T,T
    • Attribute Name : href

  3. Scraping result (stored in one field):
    							
    /web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=3IN	3i Infrastructure	258.88	0.53	0.21	0.73	2,103.48	Trade now
    /web/20190104110157/http://shares.telegraph.co.uk/quote/?epic=888	888 Holdings	164.45	1.85	1.14	-0.87	607.26	Trade now