How do I scan (as in scanf (from C) and the Scanner class (from Java)) in a webpage’s content (html) and use it as the input for my program?
string[] line = new string[length];
for (int i = 0; i < line.Length; i++) {
line[i] = Console.ReadLine();
//Can I have ReadLine read from a website not the Console?
}
e.g. I want to put a text file containing the schedules for the bus near me on web server, then access this and use it to generate the output for my application. This way I can update it and always have access to these updates.
P.S. I’m a beginning programmer, and particularly a beginning C# programmer, so I’m having trouble finding what I’m looking for as I don’t know quite what to search for.
Thanks for the help: I was able to start searching for the right thing and this worked:
class MainClass
{
public static void Main (string[] args)
{
// Create web client.
WebClient client = new WebClient();
// Download string.
string value = client.DownloadString("http://www.example.com");
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(value.Length);
Console.WriteLine(value);
}
}
You can use the method above to download the text file from your web server once it has uploaded. Just pass the URI to the
DownloadWebPagemethod and it will return the text page. If you want help parsing the text document to provide meaningful C# representations you will need to give an example of the text file and describe how you want to parse it.