Skip to content

Scraping using Regex

With Price Comparison Pro, you can scrape using CSS, xPath and Regex. In this KB, you’ll see how to scrape usuing Regex.

Many websites now provide JSON objects inside their raw HTML which you can scrape with Price Comparison Pro.

Here is an example JSON object with matching regex:

To grab the price from this, the regex would be:

/"price": "([^"]+)"/
  1. First, there are wrapping / characters to contain the expression.
  2. Next, the identifying marker before the price value. In this case it’s “price”: “
  3. Then the capturing area inside ( circular brackets ) – in this capturing area we are saying [^”]+. [] means any of the characters inside these brackets. The ^ is a special character to say any character except the following character. So [^”] means match any character except a double quote. Matching a double quote would mean we know the price value has ended. Finally, the + after the square brackets says match 1 or more character.
  4. Then we have the closing ” symbol and finally the closing /

To use Regex in Price Comparison Pro, you do so in the same way you configure CSS or xPath. Visit Settings > Price Comparison Pro > Price Comparison and choose ‘Expression Type’ of RegEXP.

Did this article answer your question?

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Join our Discord community and read the rules for a 20% discount coupon.