Scrape Value is unknown, Pls help to find the correct Select

Hey together,

i try to get the lowest possible Price from here:

So there are two options:

  • get the first index of the list or
  • get the value between the list and the comments.

I wanted to try Option two:

The Problem is: If i set everything up in Hassio, i dont get any value back. it’s just unknown.

also i tried the Python Script:

from bs4 import BeautifulSoup
import requests

# Change these 2 things
URL="https://www.keyforsteam.de/xbox-game-pass-ultimate-key-kaufen-preisvergleich/"
# This is the select line you will use in the config
SELECT=".lowPrice"
INDEX=1
# You may need to use a template after the fact...

r = requests.get(URL)
data=r.text

# Print the output of the request command to see what we even get. 
#print(data)

soup = BeautifulSoup(data,"html.parser")

# See what the select returns
val = soup.select(SELECT)
print(val)

# Try to get to the lowest thing we can...
#value = val[INDEX].text
#print(value)

# From here on out, we have to do template code to pair it down more. 

But got nothing back… What am i doing wrong?

You’re looking for an element with class="lowPrice". This works:

soup.select("meta[data-itemprop=lowPrice]")[0]["content"]

Turning that into a scrape sensor is left as an exercise for the reader :wink: .

1 Like

        resource: >-
            https://www.keyforsteam.de/xbox-game-pass-ultimate-key-kaufen-preisvergleich/
        select: "meta[data-itemprop=lowPrice]"
        index: 0
        attribute: "content"

That works, thanks for the help!

1 Like

Hi, what’s the select going to be here?

I dont think you can know that without seeing the entire source.

Also, its probably not too helpful to bump a 2 year old thread.

Sorry. I found this thread and didn’t notice the date. However, can it be done somehow?

https://community.home-assistant.io/t/scrape-value-is-unknown-help-to-find-the-correct-select/521271

No. I’ve replied to that thread.