Web intigration?

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
DEEhunter





Posts: 897
Joined: Sun Jun 19, 2005 4:04 pm
Location: 127.0.0.1
Contact:

Web intigration?

Post by DEEhunter »

How would I make my C# application receive values from a web page and store them as variables. I'm not sure if it will help but I already have the div classes that I want to receive integers from.
Image

Deviantart | My City | Wmclan | Gamertag | [url=irc://irc.halomods.com/melon]#melon[/url]
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Re: Web intigration?

Post by LuxuriousMeat »

DEEhunter wrote:How would I make my C# application receive values from a web page and store them as variables. I'm not sure if it will help but I already have the div classes that I want to receive integers
from.
Here is a very basic example.

Code: Select all

using System.Net;

//send a request to the page and get the response back
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("url");
HttpWebResponse res = (HttpWebresponse)req.GetResponse();

//store the whole page output in a string
string page = new StreamReader(res.GetResponseStream()).ReadToEnd();

//get the inner text of a certain div tag
string[] div = page.Split(new string[] { "<div>" }, StringSplitOptions.None);
string InnerText = div[1].Split(new string[] { "</div>" }, StringSplitOptions.None)[0];

MessageBox.Show(InnerText);
Image
User avatar
DEEhunter





Posts: 897
Joined: Sun Jun 19, 2005 4:04 pm
Location: 127.0.0.1
Contact:

Post by DEEhunter »

I continue to get a "Index was outside the bounds of the array." error.
Image

Deviantart | My City | Wmclan | Gamertag | [url=irc://irc.halomods.com/melon]#melon[/url]
User avatar
Altimit01




Connoisseur Snitch! Literarian 500

Posts: 947
Joined: Sun Jun 04, 2006 12:10 pm

Post by Altimit01 »

How many elements are in the string array "div"? It'd probably be a good idea to put a check making sure that the array has elements. I know that code wouldn't work on this page though. Searching for just "<div>" can cause problems when they are more like "<div align..."
Image
Download Eschaton: Halomods | Filefront | Mediafire
User avatar
DEEhunter





Posts: 897
Joined: Sun Jun 19, 2005 4:04 pm
Location: 127.0.0.1
Contact:

Post by DEEhunter »

I used div ids in it actually. But to make it more specific I tried to use <span> instead using a span ID.
Image

Deviantart | My City | Wmclan | Gamertag | [url=irc://irc.halomods.com/melon]#melon[/url]
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Post by LuxuriousMeat »

Altimit01 wrote:How many elements are in the string array "div"? It'd probably be a good idea to put a check making sure that the array has elements. I know that code wouldn't work on this page though. Searching for just "<div>" can cause problems when they are more like "<div align..."
I know it won't completely work for him, I gave an example of how to do it and he needs to modify it for it to work for him.
Image
User avatar
Altimit01




Connoisseur Snitch! Literarian 500

Posts: 947
Joined: Sun Jun 04, 2006 12:10 pm

Post by Altimit01 »

Obviously. I was just pointing out that if it was used unmodified it'd cause problems.

Anyways the best thing is to do a check before accessing the elements to make sure there are elements to access. Ubound, length or whatever the language appropriate method is. Highly recommend going through this in a debugger.
Image
Download Eschaton: Halomods | Filefront | Mediafire
Post Reply