Some tricks to get content with Hatforrent

Example :

<h1 id="title">
	
    <a href="/path/to/link-1"> link 1 </a>
    
    <a href="/path/to/link-2"> link 2 </a>
    
    <a href="/path/to/link-3"> link 3 </a>
    
</h1>
<div id="content">

    <div class="div-1"> This is the div 1 </div>
    
    <div class="div-2"> This is the div 2 </div>
    
    <div class="div-3"> <span> This is the div 3 </span> </div>
    
    <div class="div-4"> This is the div 4 </div>
    
    <div class="div-5"> This is the <a href="/hatforrent/faq" rel="nofollow"> div 5 </a> </div>
    
    <div class="div-6"> This is the div 6 </div>
    
    <div class="div-7"> This is the <a href="http://yahoo.com/" rel="follow"> div 7 </a> </div>
    
    <div class="div-8"> This is the <a href="http://google.com/" rel="follow"> div 8 </a> </div>
    
    <div class="div-9"> This is the <a href="/hatforrent/get-auto-content" rel="nofollow"> div 9 </a> </div>
    
    <img src="/img/sample-image-1.png" alt="images" title="sample image" />
    
    <img src="/img/sample-image-2.jpg" alt="images" title="sample image" />
    
    <img src="/img/sample-image-3.png" alt="images" title="sample image" />
    
</div>
    

elements with attribute ID of "id"

Usage : #id

Example : div#content

Output :

This is the div 1
This is the div 2
This is the div 3
This is the div 4
This is the div 5
This is the div 6
This is the div 7
This is the div 8
This is the div 9


elements with a class name of "class"

Usage : .class

Example : div.div-1

Output :

This is the div 1


Find unique elements that match any of the selectors

Usage : el, el, el

Example : div.div-1, div.div-2

Output :

This is the div 1
This is the div 2


Get the first and last element

Usage : tag|first, tag|last

Example : div|first, div|last

Output :

This is the div 1
This is the div 9


Get the title link (for the special case)

In some special case, there are many links in the title. You can see the example in the code above, there are 3 links in the h1 tag, and we must choose one of them.

Usage : a|x-1

"x" is the position of tag a

Example :

"link 1" : position 1 => a|0

"link 2" : position 2 => a|1

"link 3" : position 3 => a|2


Elements whose sibling index is equal to n

Usage : :eq(n)

Example : #content div:eq(2), #content div:eq(5)

Output :

This is the div 3
This is the div 6


Find elements that contain elements matching the selector

Usage : :has(seletor)

Example : div:has(span)

Output :

This is the div 3


find elements that contain the given text. The search is case-insensitive;

Usage : :contains(text)

Example : div:contains(div 4)

Output :

This is the div 4


elements with an attribute named "attr", and value equal to "val"

Usage : img[width=500], a[rel=nofollow]

Example : a[rel=nofollow]

Output :

div 5


elements with an attribute named "attr", and value starting with "valPrefix"

Usage : [attr^=valPrefix]

Example : a[href^=http:]

Output :

div 7
div 8


elements with an attribute named "attr", and value containing "valContaining"

Usage : [attr*=valContaining]

Example : a[href*=/hatforrent/]

Output :

div 5
div 9


elements with an attribute named "attr", and value ending with "valSuffix"

Usage : [attr$=valSuffix]

Example : img[src$=.png]

Output :

<img src="/img/sample-image-1.png" alt="images" title="sample image" />
<img src="/img/sample-image-3.png" alt="images" title="sample image" />