Hyperlink Formatter

Agenty HyperLink Formatter 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 Hyperlink field 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:

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:

  1. 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):

  2. Save the function and the scraping agent configuration

  3. 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 displays the text in different styles and doesn’t make any change in actual result data)

  1. 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 want to add the hyperlink for:

  4. Then, save the function and the agent configuration and go back to result tab to see the output:

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 some easy 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 below:

  1. Save the function and agent configuration
  2. Go back to result tab and see the formatted field output:

Signup now to get 100 pages credit free

14 days free trial, no credit card required!