HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: codedmind on November 17, 2014, 10:40:38 PM
-
Hy there,
What is the best way to get values from a webpage?
1 - c# and parse it (how to do it?)
2 - c# to run shell script and get the values in json format and working them with c#
3 - python, but how to scrap the html?
Thanks
-
I can't help with an example for you, but perhaps you could review the weather codes to see if they provide any useful information.
-
There are plenty of good articles on Screen Scraping in C# (https://www.google.com/webhp?q=screen%20scraping%20in%20c%23#safe=off&q=screen+scraping+in+c%23)
If the above links don't help, could you give an example of the webpage value you would like to retrieve? I should be able to create some example code for you.
-
How many of those components will work within HG? I assume you would need to use the NetHelper class and whatever methods Gene has included in it. I've found that many times using code snippets won't work when they require outside classes since they may not be compiled into HG.
-
The WebClient is a standard .NET class, Gene probably makes use of it in his NetHelper Class.
Here is a simple example:
// declare the URL we want to scrape
string url = "http://www.homegenie.it/";
string webresult;
using (System.Net.WebClient client = new System.Net.WebClient())
{
// populate webresult with the contents of the website
webresult = client.DownloadString(url);
}
// Test. Count the number of characters in the string
Program.Notify("result length", webresult.Length.ToString());
The string 'webresult' contains the HTML content of the given website. At the end I just display a count of all the characters to see if something has been retrieved.
-
I get what i want in a mixed way...
Create a python scritp that i the run in hg using c#
But now i have another problem... how to pass the value to HG as watts values so i can record the watts and the see them in the analyse?
-
But now i have another problem... how to pass the value to HG as watts values so i can record the watts and the see them in the analyse?
Check the Energy Monitor code, a few lines out of that is what you need.
-
done that but never get values into analyse graphs...
-
you have to store the value in the "Meter.Watts" parameter:
Program.Parameter("Meter.Watts").Value = <value_read_from_sensor>;
stats will be shown after 5 minutes sampling.
Also read this:
http://www.homegenie.it/forum/index.php?topic=227.msg1201 (http://www.homegenie.it/forum/index.php?topic=227.msg1201)
g.
-
Thank you.
Is woking now.
Gene using c# hg has any helper to work with json strings? What is the best way?
-
Try this:
// example json input string
string jsonText = "{ \"Bar\" : \"something\" }";
// deserialize as dynamic
dynamic foo = JObject.Parse(jsonText);
// get the Bar field value
string bar = foo.Bar;
// output the result
Program.Notify("JSON Test", bar);
reference: http://thewayofcode.wordpress.com/2012/09/18/c-dynamic-object-and-json-serialization-with-json-net/ (http://thewayofcode.wordpress.com/2012/09/18/c-dynamic-object-and-json-serialization-with-json-net/)
Have you considered using a Javascript app instead of a c# one? Perhaps it's easier to code.
g.
-
How can i make an javascript program to load a webpage and then serialize the html content?