HyperLinkFormatter

Agenty HyperLinkFormatter function is used to format the agents text fields into clickable-links, the formatter function can be used in existing field as well a new field can be added to keep both, the text and formatted hyperlink to display. There are 3 ways to use this function to add a hyperlink URL in the result table : 

  1. Without parameters
  2. Static values in parameters
  3. Dynamic field names in parameters

In this tutorial, we are going to try each of these to see how the hyper link fields formatter works :

Before:

The scraping agent consider all the fields DataType as TEXT by default, so If you see the screenshot below the images src, url is all in plain text format :

hyper link formatter

 

Without parameters

  1. Edit the scraping agent by clicking on the "Edit" tab and go to "Fields and Collections" section
  2. Go to the field ProductCartLink and click on the "Edit" button to edit this field
  3. Now, click on the "Add Formatter" button as in screenshot below
    add hyper link formatter
  4. The below modal dialog box will appear, where we need to select the HyperLinkFormatter in drop-down and then leave the parameter as blank(by-default)
    hyper link formatter box
  5. Save the function and the scraping agent configuration
  6. Go back to result tab (Remember : There are no need to re-run the agent to apply the changes we made in formatter, because the formatter function just display the text in different styles and doesn't make any change in actual result data)
    after hyper-link formatter
  7. So, when we use the HyperLinkFormatter function and don't pass any parameter, the function just convert that field values into a click-able link if the value is a valid hyperlink (starts with http or https)

Static values in parameters

We can also use the HyperLinkFormatter function to add a static click-able link field in agent result to go to any website or url you want. In order to do that, we just need to add a new field and then the formatter with static values in href and text parameters

  1. Add a field, name it something as I did "AmazonURL"
  2. Click on the "Add Formatter"
  3. Select the "HyperLinkFormatter" and enter the static values in href and text parameters you wants to add the hyperlink for
    static values in parameters
  4. Then, save the function and the agent configuration and go back to result tab to see the output
    after static value in hyperlink formatter

Dynamic field names in parameters

We can also use the HyperLinkFormatter function to create links dynamically by using the values in other fields in same row. For example, I can create a hyperlink field using the anchor text in ProductName and href in ProductCartLink field dynamically for each row. The only difference is, we need to use the field name in parameters and the function will automatically pick the value in corresponding row and create the link in result table. For example, follow the steps with me to convert the ProductName existing field into link with URL from ProductCartLink for each row.

  1. Edit the scraping agent by clicking on the "Edit" tab
  2. Go to "ProductName" field and click on the "Edit" button to edit this field
  3. Click on the "Add formatter" function to add the formatter
  4. Now, enter the ProductCartLink field name in href parameter and ProductName field name in text parameter, as in screenshot belowfield names for dynamic hyperlink formatter
  5. Save the function and agent configuration
  6. Go back to result tab and see the formatted field output
    dynamic field hyperlink in agent result