IF/Then/Else and something other then null

Sometimes when I am scraping certain websites, some of the data would be in a different spot depending on different factors.

One example:
if it's an Organization or Individual, or if they have a Legal Business Name & Doing business as another (same with parent companies) things are categorized differently and are in different spots making it hard to scrape (lots of regex).

It would be nice just to have some run if this element is there do this, if not this.

Also could you add a field for each selector to have a default text if null?

If I am scraping multiple things on a page, I might need to go back and either delete all the nulls, change all the nulls in 1 field to something else, or do both at the same time.

It would be a lot easier if we could specify the null text at the selector level.


You can do that by using CSS selectors and setting multiple selectors for a single selector separated by comma.

For example there are 2 types of organizations - A and B.

If the organization is A it's title in <h1 class="title">Title</h1> element.
If the organization is B it's title in <h2 class="title">Title</h2> element.

Selector for title would look like this: body:not(:has(h2.title)) h1.title, body:not(:has(h1.title)) h2.title .

If site has both titles then scraper won't scrape anything though.

Alright thanks,

I will try it out


Took some playing around to match my needs, but so far it is working great!

Thanks a lot @KristapsWS