Hey Guys,
I am trying to get a value from a website. 3142
The value being 3142.
I have been successful in accessing the website. I have also been successful in grabbing a value using "string search". The problem i am having at is that the value is static. That indicates to me that the value is not being updated. If anyone has any ideas please let me know. Thank you so much!
void Start () {
//curDemand = maxDemand;
InvokeRepeating ("demandCalc", 1f, 1f);
string url = "https://www.energex.com.au/the-network/understanding-the-network/peak-demand";
WWW www = new WWW(url);
StartCoroutine(WaitForRequest(www));
string input = "3166";
string search = "";
int p = input.IndexOf (search);
if (p >= 0) {
// move forward to the value
int start = p + search.Length;
// now find the end by searching for the next closing tag starting at the start position,
// limiting the forward search to the max value length
int end = input.IndexOf ("", start);
if (end >= 0) {
// pull out the substring
string v = input.Substring (start, end - start);
// finally parse into a float
float value = float.Parse (v);
Debug.Log ("Value = " + value);
curDemand = value;
} else {
//Debug.Log("Bad html - closing tag not found");
}
} else {
Debug.Log ("donations span not found");
}
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null) {
Debug.Log ("WWW Ok!: " + www.text);
//site.text = "site" + www.text;
} else {
Debug.Log ("WWW Error: " + www.error);
}
}
↧