Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by NG_Phteven · Dec 22, 2015 at 06:42 AM · valueonlinewebsiteget

Get a numeric value from a website

Hey Guys, I am trying to get a value from a website.

 <span id="insert-graph">3142</span>

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 = "<span id=\"insert-graph\">3166</span>";
         string search = "<span id=\"insert-graph\">";
         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 ("</span>", 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);
         }
     }
 

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image _Yash_ · Dec 22, 2015 at 06:55 AM 0
Share

What i can see from this is that you are not using www.text ins$$anonymous$$d you are using a fixed input variable.

int p = input.IndexOf (search);

should be

int p = www.text.IndexOf (search);

avatar image NG_Phteven _Yash_ · Dec 22, 2015 at 07:08 AM 0
Share

Hey Yash, Thanks for your comment. I have changed the lines you have suggested. I am however getting this error now: UnityException: WWW is not ready downloading yet.

avatar image _Yash_ NG_Phteven · Dec 22, 2015 at 10:00 AM 0
Share
 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));
          
          
      }
      IEnumerator WaitForRequest(WWW www)
      {
          yield return www;
          // check for errors
          if (www.error == null) {
              Debug.Log ("WWW Ok!: " + www.text);
             
              string input = www.text;
          string search = "<span id=\"insert-graph\">";
          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 ("</span>", 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");
          }
  
          } else {
              Debug.Log ("WWW Error: " + www.error);
          }
 
         
      }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NG_Phteven · Dec 23, 2015 at 03:08 PM

Alright, I'm pretty sure I figured out the reason why we can't access that number. The script works fine. The problem is with the webpage itself or rather with the way the number is produced. Since the number isn't static and gets updated, it's not actually in the html source properties of the webpage. This means that the number is received from a server or similar. Since it's not in the html source code, we can't access it because the html source is what we access using the script.

The easiest way is to contact the admin of the page and ask for a way to let you access that number. I assume it would be another html site with just the number in it which actually gets called by the main site.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityWebRequest, C# request.accept equivalent? 0 Answers

How to get variable by name(string typed in inspector) in array with index from another script? 0 Answers

Get keyframe values of animations via script 1 Answer

How to GET and parse data from website? 0 Answers

Getting Values In Unity From Webpage 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges