2 Replies - 16848 Views - Last Post: 21 October 2011 - 04:22 AM Rate Topic: -----

#1 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Read HTML source or get JavaScript variable from URL

Posted 20 October 2011 - 06:13 PM

I am attempting to get the contents of a Javascript variable from a webpage to get the games owned by a particular user by accessing their PUBLIC profile. By having it public the user agrees others can search and view detail suchs as games owned or other applications and this is voluntary, I make no attempt to gain user data or access PRIVATE profiles so this isn't hacking or anything that could be considered spyware.

In the following code I realize the URL is not added in but this is on purpose for posting the code. I am wondering if I am doing something wrong or should be using an alternative method to access the page source. If it does return data on a user it missed sometimes 80% of the games the user actually owns. I know the games are in a Javascript array if that helps but if not when I view the source with Firefox I see each game in a list with each line starting with the word game.

Again this accesses only PUBLIC data and does NOT attempt to gather any personal information from the user and doesn't even require authentication to access the data I am attempting to list with this application.

Code I am using:
        private static void GetGamesList(string Username)
        {
            try
            {
                WebRequest wc = HttpWebRequest.Create(url + Username);
                wc.Method = "GET";

                List<string> content = new List<string>();
                using (StreamReader sr = new StreamReader(wc.GetResponse().GetResponseStream()))
                {
                    while (sr.ReadLine() != null)
                    {
                        if (sr.ReadLine().Contains("game"))
                        {
                            content.Add(sr.ReadLine());
                        }
                    }
                }

                if (content.Count > 0)
                {
                    foreach (string line in content)
                    {
                        Console.WriteLine(line);
                    }
                }
                else
                {
                    Console.WriteLine("User has no games associated with their account.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }


This post has been edited by blank_program: 20 October 2011 - 06:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Read HTML source or get JavaScript variable from URL

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Read HTML source or get JavaScript variable from URL

Posted 20 October 2011 - 07:15 PM

Reading source is easy. What you're doing is getting the pages source. Are you saying that the returned HTML is different than the HTML you see when you view source in the browser?

As to Javascript, the httpwebrequest does not render it. So you could download the js code, bu it will not be executed at all.
Was This Post Helpful? 0
  • +
  • -

#3 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Re: Read HTML source or get JavaScript variable from URL

Posted 21 October 2011 - 04:22 AM

Yes the source, or at least the list of games, is different in my application than it is in the browser.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1