Multiscrape - 2 questions

I’m trying to get the snow fall from a website.
The class for the data I need is .number for all of the data.
I’m able to grab the first instance, but when using nth-child(n) (2, etc) the data isn’t pulling.
Question 1: what am I doing wrong?
Question 2: this is pulling the string x" for x inches of snow. I want to split out the double quotes but am rather certain value.split (""") isn’t correct. I also tried using the ascii code with no luck.
image
image

So I’ve worked through part of the challenge.
If you look at the resource URL you’ll see I’m trying to grab data from a table.
I am now successful with grabbing the first row.
But of course, I also want the second row, and things fall apart here.
If I just understood the actual logic here.
This is my updated code, the commented out lines do not work.

- name: UT Snow Scraper
  resource: https://townlift.com/weather-snow-report/
  scan_interval: 5000
  sensor:
    - unique_id: deer_valley_inches_of_snow_24hrs
      name: Deer Valley Snow Report Fall Last 24hrs
      select:  ".col-xs.snow-report__stat > .number"
#      on_error:
#        value: "Not Yet" 
#      value_template: '{{ value.split("&@34")[0] }}'
    - unique_id: deer_valley_inches_of_snow_48hrs
      name: Deer Valley Snow Report Fall Last 48hrs
      select: ".col-xs.snow-report__stat:nth-child(3) > .number"
#      value_template: '{{ value.split(""")[0] }}'
    - unique_id: deer_valley_snow_base
      name: Deer Valley Snow Base
      select: ".col-xs.snow-report__stat:nth-child(4) > .number"
#      value_template: '{{ value.split(""")[0] }}' 
    - unique_id: deer_valley_current_temp
      name: Deer Valley Current Temp
      select: ".col-xs.snow-report__stat:nth-child(5) > .number"
#      value_template: '{{ value.split("°")[0] }}' 
#    - unique_id: park_city_inches_of_snow_24hrs
#      name: Park City Snow Report Fall Last 24hrs
#      select:  ".snow-report__item:nth-child(1) > .col-xs.snow-report__stat:nth-child(3) > .number" 
#      value_template: '{{ value.split("&@34")[0] }}'
#    - unique_id: park_city_of_snow_48hrs
#      name: Park City Snow Report Fall Last 48hrs
#      select: ".snow-report__item:nth-child(1).col-xs.snow-report__stat:nth-child(4) > .number"
#      value_template: '{{ value.split(""")[0] }}'
#    - unique_id: park_city_snow_base
#      name: Park City Snow Base
#      select: ".snow-report__item:nth-child(1).col-xs.snow-report__stat:nth-child(5) > .number"
#      value_template: '{{ value.split(""")[0] }}' 
#    - unique_id: park_city_current_temp
#      name: Park City Current Temp
#      select: ".snow-report__item:nth-child(1).col-xs.snow-report__stat:nth-child(6) > .number"
#      value_template: '{{ value.split("°")[0] }}'

Not tested but:

  • Try escaping the double quotes like this: .split("\"")
  • Try something like this for on_error:
on_error:
  value: default
  default: "Not yet"

(‘strategy’ would be a better name instead of value)

1 Like