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 TheShadyColombian · Oct 09, 2015 at 03:28 AM · c#wwwwebsite

get value from website

Hello! I really need some help. I need to get a value from a website. the website is http://www.pegboardnerds.com/ and I need to get the value from

 <span id="donations">8470.71</span>

which is shown as: 8470.71

any way or method possible is fine by me, (even converting it all to a string and then doing some un-optimized witchcraft) but a really important part of my game depends on that value. I'm also not the direct owner of the website so I can't edit anything (however I am allowed to use it, so don't worry about any legal issues, etc)

If possible, I'd really appreciate any help to be in C#

thanks in advance for any help, everyone!

Comment
Add comment · Show 2
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 monstercatjuan · Oct 09, 2015 at 04:07 AM 0
Share

@DaveCarlile how do I parse the value?

avatar image NG_Phteven monstercatjuan · Dec 22, 2015 at 11:34 AM 0
Share

you can use

 string v = input.Substring (start, end - start);
 float value = float.Parse (v);
 Debug.Log ("Value = " + value);

to parse a value

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Oct 09, 2015 at 03:56 AM

Use the WWW class to grab the web page, then search for the string you're interested in and parse out the value.

There's a number of ways you could parse the html. Your best bet would be to use something built-in to .NET to convert it to an object model, or some library to do that. Or you could parse it manually...

Here is some really crappy code to do it... some would argue that you should use regular expressions or something.

 string input = "blah blah blah<blah><span id=\"donations\">8470.71</span></blah>";

 string search = "<span id=\"donations\">";
 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);
     }
     else
     {
         Debug.Log("Bad html - closing tag not found");
     }
 }
 else
 {
     Debug.Log("donations span not found");
 }


Comment
Add comment · Show 16 · 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
avatar image TheShadyColombian · Oct 09, 2015 at 01:09 PM 0
Share

That sounds perfect, and I already started with that, but I don't know how to parse out the value. could you help me with that?

avatar image Dave-Carlile TheShadyColombian · Oct 09, 2015 at 01:13 PM 0
Share

Heh - that was fast... I was updating the answer with some bad code.

avatar image TheShadyColombian Dave-Carlile · Oct 09, 2015 at 01:14 PM 0
Share

Nice! thank you so much!

Show more comments
avatar image Dave-Carlile · Oct 09, 2015 at 01:38 PM 0
Share

Oh, is it updating the value using javascript/ajax (or whatever they're calling that nowadays)?

You'd have to look through the page source, or chrome dev tools or something and find the javascript that's executing and figure out what it's doing. It's possibly calling back to the server to grab the value and update it periodically.

avatar image TheShadyColombian Dave-Carlile · Oct 09, 2015 at 01:40 PM 0
Share

Alright. I'll do my best but there's about 6 very long scripts. Anyway, thanks for all the help! ps. If I find where it's getting the value from, how can I grab that?

avatar image Dave-Carlile TheShadyColombian · Oct 09, 2015 at 02:14 PM 0
Share

It may be more html, or it might be json. $$anonymous$$ore parsing :).

avatar image NG_Phteven · Dec 22, 2015 at 11:26 AM 0
Share

Hey xXJuanXx,

Did you figure out a solution? I am having the exact same problem as you!

avatar image TheShadyColombian NG_Phteven · Dec 22, 2015 at 02:18 PM 0
Share

Hey! Dave Carlile's script worked fine for me, but the only problem I was having was that the website I tried it on used a weird script to animate the value so that's the only reason it didn't work.

(It still doesn't work, and I actually had my idea stolen so I'm not bothering to fix it, but this script should work in every other situation)

avatar image NG_Phteven TheShadyColombian · Dec 22, 2015 at 11:23 PM 0
Share

That's very unfortunate that you didn't get it to work and then had your idea stolen :(.

I Have adopted the script and changed the variables to suit my needs. No luck however. Would you $$anonymous$$d clarifying what I need to put into the string input? Is it the whole span like this "<span id=\"insert-graph\">3166</span>"; or is there more to it? I am starting to think that I need to be more specific about where to find that span? The html I want is embedded quite deeply into the site. Hope it's not too much trouble. Thanks so much mate!

Show more comments

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

34 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 avatar image

Related Questions

Get Internet Year PHP 0 Answers

[WEBGL] Post json - complicated structure 0 Answers

WWWForm - .AddField vs .headers 0 Answers

Script in Unity responding incorrect values 0 Answers

Writing Files to Android Device 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