Show web content as sensor or camera?

Does anyone know a way to extract web content?

I would like to extract the local gas prices from the following web page:

I prefer a sensor because that makes it easier to setup some automations based on the current price value. A “camera” with only the part rectangled in red would also be great.

Link to page:

You could try to write your own custom_component.
With this component you e.g. could use BeautifulSoup for finding the places of the

p class=“font-green”>[…]</p

e.g. following quick and dirty code:

u = urlopen(url)
html =‘utf-8’)
soup = BeautifulSoup(html, “html.parser”)
mygreenvalues = soup.findAll(“p”, { “class” : “font-green” })
for line in mygreenvalues
print (line.getText())

or you could use a Command line sensor and write a script

Hope this helps.

1 Like

There is actually a component for that called the scrape sensor

Try this @Bob_NL



Thanks for the information.
Now I can delete one of my custom_components :slight_smile:

@stunts1337 thanks.

I managed to extract the data:

  - platform: scrape
    name: Shell Express
    select: ".price-actual"
    unit_of_measurement: "EUR/L"

I’m struggling with the value_template part. Currently it shows as:

1,549 EUR/L

Combined with my unit_of_measurement I get:

1,549 EUR/L EUR/L

I would only like the value in my sensor, without the EUR/L. How can I extract this?

try adding
value_template: '{{ value.split(" ")[0] }}'

1 Like

Thanks, working!