Value template for Multiscrape

Hi all, trying to learn how to scrape websites and i’ve tasked myself with trying to get the output from yr.no weather and report the clear nights for my astronomy.

I have the basics working but i am stuck on how to write a value template that accommodates for reading a heading value when the values change.

to explain in detail, i want to read the “cloud cover %” value, but some times this is in the 5th position and it could be in the 9 & 10th position from the end depending if the other values are single digit or double digit outputs.

If someone has an idea on a means to extract what I’m after i’d appreciate it

- resource: https://www.yr.no/en/details/table/2-2144355/Australia/Victoria/Shire%20of%20Nillumbik/Wattleglen
  scan_interval: 3600
  headers:
    User-Agent: Mozilla/5.0
  
  sensor:
    - unique_id: astroweather
      name: astro_weather_wg
      select: "#details-page__table > div > div:nth-child(4) > div > div.fluid-table__scroll-container > table > tbody > tr:nth-child(1)"
      value_template: "{{ value[-5] }}"
    
    - unique_id: astroweather1
      name: astro_weather_wg1
      select: "#details-page__table > div > div:nth-child(4) > div > div.fluid-table__scroll-container > table > tbody > tr:nth-child(2)"
      value_template: "{{ value[-5] }}"
    
    - unique_id: astroweather2
      name: astro_weather_wg2
      select: "#details-page__table > div > div:nth-child(4) > div > div.fluid-table__scroll-container > table > tbody > tr:nth-child(3)"
      value_template: "{{ value[-5] }}"

Edit your post to mark up the code properly as it is difficult to read without the proper indentation etc.

Why would the order or number of table cells change with the number of digits used for the various values? Kind of difficult to understand if you cannot provide sample data of this page to properly show the differences in expected inputs.

Mayhem,

Fixed the code, couldn’t for the life of me find the button that formatted the code.

As for the sample data, the link is in the “resource” section of the code snippet

Here it is again for reference:

resource: Yr - Wattleglen - Detailed weather forecast as a table

Yes, but that is only one instance of sample data. Again from your first post:

I don’t understand why the number of digits used anywhere in the tables would throw off the order of which column or row you’re looking for, hence the necessity for seeing how the data may or may not change…

I suspect the OP is trying to treat it as a character string to split it.

@seafurymike A simple scrape sensor with a select of:

td.hourly-weather-table__cloud span span span

and an index of 5 × the row you want (starting from 0) will do it.

Current table:

and using an index of 15 for row 3 (the fourth row!) gives me this:

image

The 5 multiplier is because all of the subsequent numbers (fog etc) are the same class.

No value_template is needed because the select has correctly pulled just the data you want.

Stop using tools to work out the select statement, as they always give you a mess. Here’s the HTML:

Your data is three spans deep within the first td.hourly-weather-table__cloud on each row.

A far better solution would be to use machine-readable data via their API. Scraping HTML should be a last resort.

Thanks Troon.

I am new to all of this and i’m trying to build my knowledge, which in part means i tend to go down the path i know.

Thanks for the recommendations on how to parse this data. I will have a go at this method today