Bob_NL
(Bob Visser)
April 6, 2017, 8:01pm
1
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:
http://www.shell.nl/motorists/shell-express/shell-express-stations.html#iframe-L25sX25sL3N0YXRpb25z=true&iframe=L25sX25sL3N0YXRpb24vc2UtbmlldXdlcmtlcmstYWFuLWRlbi1panNzZWw=
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)
try:
html = u.read().decode(‘utf-8’)
finally:
u.close()
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
2 Likes
@stunts1337
Thanks for the information.
Now I can delete one of my custom_components
Bob_NL
(Bob Visser)
April 12, 2017, 5:37pm
5
@stunts1337 thanks.
I managed to extract the data:
- platform: scrape
resource: https://www.shellexpress.nl/nl_nl/station/se-nieuwerkerk-aan-den-ijssel
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?
Airpal
(Arijit Pal)
April 12, 2017, 5:51pm
6
try adding
value_template: '{{ value.split(" ")[0] }}'
1 Like