When extracting a list of values, products for example, they are sometimes labelled with a sale tag. If you want to check for this tag and flag these products in your run results, ParseHub can extract a custom value for you. In this tutorial, we will demonstrate how to label a value in your run results based on the presence/non-presence of a value on the page.
For this example, we are going to be using Amazon's Deals and Promotions page.
Example 1: Labelling a value if an element appears on the page
Let's say we want to flag products that are being sold and shipped by Amazon with the value "Y"
1. Using the Select command that is automatically generated for you, select the first product's name by clicking on it. It will get highlighted in green, and similar elements will get highlighted in yellow. Click on one of the yellow highlights around another product's name to select it as well. Keep clicking on products' names until all products on the page are selected.
2. Click on the + sign next to "Select product" and add a Relative Select command.
3. Scroll down to a product that is sold and shipped by Amazon. With the Relative Select command active, click on the orange highlight around one of the product names, and then click on the text underneath it that says "Ships from and sold by Amazon.com". Keep doing this until all of these labels are selected.
4. Click on the + sign next to "Relative flag" and add an Extract command.
5. In the Extract command's settings, type in "Y". Once that is added, you'll see in your data preview that all products that are sold and shipped by Amazon are marked with the value of "Y", and products that are not sold and shipped by Amazon have blank cells.
BONUS TIP: If you wanted ParseHub to execute a command based on the flag value, you can add a condition by clicking on the + sign next to "Select page".
Example 2: Labelling a value if an element does not appear on the page
Let's say we want to flag products that are not being sold and shipped by Amazon with the value "N"
1. Like in the example above, we are going to select all of the products on the page by using the Select command that is automatically generated for you.
2. Click on the + sign next to "Select product" and add an Extract command.
3. In your Extract command's settings, type in "N". This will extract the "N" value under every single product on the webpage.
4. Now, add a Relative Select command to your project by clicking on the + sign next to "Select product". Use it to select the "Ships from and sold by Amazon.com" label under the products. Rename this Relative Select command to the same name as your Extract command that is extracting your flag value ("flag" in this case).
This command will overwrite the value from the "Extract flag" command. Now, all products that are not sold and shipped by Amazon are flagged by the value "N" in your results preview, while products that are sold and shipped by Amazon have "Ships from and sold by Amazon.com." next to them.
BONUS TIP: If you wanted ParseHub to execute a command based on the flag value, you can add a condition by clicking on the + sign next to "Select page".