Web intigration?
Web intigration?
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.
- LuxuriousMeat
- Posts: 824
- Joined: Thu Nov 03, 2005 6:43 pm
- Location: zzzzzzzzzzzzzzzz
- Contact:
Re: Web intigration?
Here is a very basic example.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.
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);
- LuxuriousMeat
- Posts: 824
- Joined: Thu Nov 03, 2005 6:43 pm
- Location: zzzzzzzzzzzzzzzz
- Contact:
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.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..."
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.
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.