Example 1: Getting HTML Content and Attributes

The example below shows how you can obtain HTML content and attributes in one go using the get keyword.

Code on the desktop site page:

<html>
 <body>
   <a href="http://example.com">Sample link.</a>
 </body>
</html>

Defining the get keyword:

{
 link: {
   xpath: '//a',
   get:   ['text', '@href']
 }
}

You can use the link.text parameter in your template/snippet code and get the “Sample link.” text in the result.

The link._href parameter, used in your template/snippet code, will return “http://example.com”.