[SOLVED] Sensor Scrape - need help with attribute

Hey all!

I’m completely stuck with the following… want to scrape the data-value 4617 from the following code:

    <div class="widgetHead">Current PV Power</div>
    <div class="widgetSubHead"></div>
    <div class="widgetBody">
        <div class="mainValue">
            <img class="powerGaugeBackground" src="/Images/Dashboard/gauge.png" alt="" />
            <img class="powerGaugePointer" src="/Images/Dashboard/currentPlantPowerPointer.png" alt="" />
            <span
                class="mainValueAmount" 
                data-peak="7600"
                data-value="4617"
                data-timestamp="2019-04-19T14:45:00">-</span>
            <span class="mainValueUnit"></span>
        </div>
    </div>
    <div class="widgetFooter">
        
    </div>
</div>

Full source of the URL that I want to scrape : https://pastebin.com/KZJtHydi

I checked the docs, looked at the css selector stuff, … googled some things… no solution so far. So I’m hoping that this community can find a solution.

Thanks!

I’m going a bit blind without seeing the actual page so this may not work:

  - platform: scrape
    resource: ENTER_URL_HERE
    name: Power_Value
    select: '.mainValueAmount'
    attribute: data-value
1 Like

That did the trick! And looking at it now, this was quite clearly mentioned in the docs :slight_smile:
Thanks!

1 Like

Hey all
I need to know the status if a light is on with the scrape sensor from the following code:
When the light Led vensters is on it is colored in gray like this:

And I have this in the config without succes :

 - platform: scrape
    resource: http://192.168.0.141:8080/#entry/0/4
    name: ikke1
    select: "Led vensters"
    value_template: '{{ li-negative }}'
    # Request every hour
    scan_interval: 10
    headers:
      -H 'Cookie: PHPSESSID=1sudbnm3ipdea31uv89sp734n0' \
      -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
      -H 'Upgrade-Insecure-Requests: 1' \
      -H 'Host: 192.168.0.141:8080' \
      -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15' \
      -H 'Accept-Language: nl-be' \
      -H 'Accept-Encoding: gzip, deflate' \
      -H 'Connection: keep-alive'"

Suggestions are welcome!

you need to read the docs.
select: "Led vensters" is not going to work as Led vensters is not a class but a text.
On the basis that the class this element is displayed under doesn’t appear to have a unique name, you’ll probably need to use something like div:nth-of-type(x) where x is the nth occurence of that div tag in the doc. You will also need to ensure that position never changes, e.g. if a new item is dynamically displayed above that element, then you’ll end up with a different value that will not match Led vensters…
There may be a way to see if you can use .data-action="../../../action/6640/" as a selector, but I’ve not checked how that would be achieved.
More info on how BeautifulSoup works on their doc homepage: https://www.crummy.com/software/BeautifulSoup/bs4/doc/

ok, thanks
I’Il try this tonight

I am getting the unknown value with this configuration :

 - platform: scrape
    resource:  http://192.168.0.141:8080/#entry/0/4
    name: ikke1
    select: "div:nth-of-type(6640)"
    value_template: '{{  li-negative }}'
    # Request every hour
    scan_interval: 10
    headers:
       -H 'Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5' \
       -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
       -H 'Upgrade-Insecure-Requests: 1' \
       -H 'Host: 192.168.0.141:8080' \
       -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15' \
       -H 'Accept-Language: nl-be' \
       -H 'Accept-Encoding: gzip, deflate' \
       -H 'Connection: keep-alive'"

Any idea what could be wrong here? Is it the value_template?