Scrape sensor improved - scraping multiple values

Hi all, just wanted to follow-up if anybody has an idea on how to solve this?

My library uses the same kb platform :slight_smile:
So I gave it a try but it seems to be some kind of OAuth implementation, and thatā€™s quite complex and not supported by Multiscrape, unfortunately.

1 Like

Not possible yet, but a nice feature! Please create a feature request on github.

Iā€™m excited to share some new features and improvements in v7.1.2 which I just released. Hereā€™s whatā€™s new:

:sparkles: New Feature: Form Variables

A big shoutout to @jeremicmilan for his incredible dedication to this feature! :clap: Iā€™ve added Form Variables to Multiscrape, allowing you to scrape the (token of a) page returned after logging in on some sites (specifically PHP). This token can then be sent in a header for authentication or other purposes. For all the details, make sure to check out the README! :books:

:cookie: New Feature: Cookies support

You asked, I delivered! The long-awaited support for cookies is finally here! :tada: Now, all cookies returned in HTTP sessions are automatically transferred to the next request. Plus, Iā€™ve added logging so you can easily see which cookies are set. Sweet, right? :cookie:

:robot: Automated Tests!!

Iā€™m taking stability to the next level with the newly set up automated testing infrastructure! The first 2 automated tests have been added to Multiscrape, ensuring even more reliability in the future. Continuous improvements are on the way! :hammer_and_wrench:

As always, a huge thank you to the amazing community for your continued support and feedback. Happy scraping! :spider::computer:

PS: If you enjoy Multiscrape, please consider supporting me and buy me a coffee.

3 Likes

done, thank you!

I took note of the form variables with this release. Is it limited to capturing form response header values only? I am seeking to capture the csrftoken value from the form response page for use in the subsequent resource url.

Thatā€™s exactly what itā€™s meant for!

Now available in v7.2.0!

New Feature: Raw HTML Scraping with Multiscrape :globe_with_meridians:

Iā€™m excited to announce that it is now possible to scrape raw HTML in Multiscrape! This feature has been a recurring request over the years, and Iā€™m happy I could finally implement it. :tada:
It could for example be used to for displaying rich content on a markdown card.

A new configuration option for selectors has been added called extract. It is optional and can have these values:
- Text (default): Extracts plain text, as you are used to. :memo:
- Content: Returns the content of the selected tag. :scroll:
- Tag: Returns both the content and the tag itself. :label:

With this feature, your sensors (or attributes) can now have a state/value like:

<p>This is an <b>example</b> of what can be scraped with the <i>extract</i> feature.</p>

Thank you for your continued support, and happy scraping! :partying_face:

2 Likes

Would love to see OAuth support, as this will probably solve the issue of scraping Water-link for water meter data.

Hi all, I am trying to integrate sensors using Multiscrape, but canā€™t get it to work.

Situation:
HA running in Docker on Synology, Multiscrape installed from HACS

Iā€™m trying to read sensors from my floor heating controller, for which I used to run a python script on my syno: GitHub - Sir-Bacon/UMR2toMQTT: Python routine to read out UMR2 floorheating controller and publish values to MQTT
That would readout the json from the website and send it to MQTT for HA to pickup. That has stopped working recently and when I saw Multiscrape, my thought was that I could pull the scraping inside HA. And then stop using the script, much easier.

Now Iā€™m trying to get this working, but failing sofar. When I drop my code in the Developer tools template I get the error ā€˜UndefinedError: ā€˜value_jsonā€™ is undefinedā€™. I believe this means the json is not valid. But I know it is, it has always worked like that.

The following code does not work:

multiscrape:
  - name: Multiscrape Data
    resource_template: 'http://192.168.2.31/get.json?f=$.status.*'
    scan_interval: 10
    log_response: true
    sensor:
      - unique_id: multiscrape_VVW_mode_test
        name: Vloerverwarming Modus
        value_template: '{{ value_json.status.outputs.heater.mode }}'

sensor:
  - platform: rest
    resource: 'http://192.168.2.31/get.json?f=$.status.*'
    name:  Rest VVW mode test
    value_template: '{{ value_json.status.outputs.heater.mode }}'

This is to test with 1 value, I want to extract at least 5 values/states from the json.

Any pointers in which direction I need find a solution? Much appreciated.

Since you have enabled debugging, did you check that Multiscrape is indeed getting a JSON as response? You can check page_response_body.txt in homeassistant/multiscrape/ā€˜name of sensorā€™.
I have had issues with square brackets at the start and end of JSON, so I removed them with a replace.

I wonder if this ever got resolved? I am currently using Multiscrape successfully to log in to a website to retrieve some values, but I can also perform actions on the website (after logging in) by getting a URL. I canā€™t have this URL scraped, because that means that the action is performed e.g. when I restart Home Assistant. But without the form submit functionality of Multiscrape, thereā€™s no log in

Any ideaā€™s on how to only call the URL ad hoc or how to pass on the headers to e.g. a rest command?

No it is not. I donā€™t understand how the integration is able to write a file but not to create a sensor.

Good to know Iā€™m not the only one struggling with that. Would you mind sharing how you did the workaround by opening the debug files with the responses and extract them?

I havenā€™t been able to look at this yet, but in v8.01 which is currently available as a pre-release, you can set the scan_interval to 0 and the action will never be performed (not even on startup), unless manually triggered. Does that help or is there anything else in a rest command that you cannot achieve with multiscrape?

1 Like

I donā€™t understand how the integration is able to write a file but not to create a sensor.

Iā€™m looking forward to your pull request :wink:

That looks like something I can work with. I will test when I find the time!

Anyone got issues with Powershop NZ? Something changed around the 30th September and now I have no sensors. Logs show the following:

2024-10-01 11:20:09.418 ERROR (MainThread) [custom_components.multiscrape.coordinator] Powershop # Exception in form-submit feature. Will continue trying to scrape target page.
[custom_components.multiscrape.coordinator] Powershop # Updating failed with exception: 
2024-10-01 11:20:19.433 ERROR (MainThread) [custom_components.multiscrape.sensor] Powershop # Powershop Off Peak # Unable to scrape data: Skipped scraping because data couldn't be updated 

I had added verify_ssl: false to the form section and rebooted but alas today, sensors are unavailable again.

Partial config below:

- resource: 'https://secure.powershop.co.nz/rates'
  name: Powershop
  log_response: true
  scan_interval: 43200
  form_submit:
    submit_once: true
    verify_ssl: false
    resource: 'https://secure.powershop.co.nz'
    select: ".content > form"
    input:
      email: !secret powershop_user
      password: !secret powershop_pass

v8.0.2 :sunny: Startup performance & restoring values

:warning: This release contains some important changes! :warning:

:tada: Iā€™m super excited about this new release! Itā€™s containing some changes that are not breaking but do make Multiscrape work slightly different than before. :rocket: Read on!

:zap: Performance Boosts!

This release brings huge improvements to startup performance. While itā€™s a big leap forward, you might not feel the impact as much because of the great improvements in Home Assistant over the past few months. But trust me, itā€™s fast! :zap:
On my production system:

:arrows_counterclockwise: Restoring Previous Values

Both sensor states and attribute values are now restored after a reboot, meaning youā€™ll be right back where you left off! No more waiting for new scrapes to kick in to get your data back after restarting. :arrows_counterclockwise: (It is also restored when you set ā€˜lastā€™ in ā€˜on-errorā€™)

:pause_button: No More Scrapes with scan_interval: 0

Hereā€™s a subtle but important change: if you set scan_interval to 0, Multiscrape will no longer scrape on startup. Previously, it would still initiate a scrape on startup, but now it stays idle just like youā€™d expect. :stop_sign:

As always, thanks for using Multiscrape! Let me know how itā€™s working for you. Happy scraping! :spider::computer:

Other notes

  • I want to dedicate this release to @madelena , Product Manager @ Nabu Casa, as she (unknowingly) was one of the main triggers for this release. Seeing Multiscrape pop up here was painful :sweat_smile:: Release party 2024.4
  • Happy with Multiscrape? Consider to buy me a coffee or sponsor me on Github!
  • Check out my other custom integration: MeasureIt!
2 Likes