Creating a web application that finds some tags and displays them
I've run into some errors and I'm completely stuck!
Here is my code:
- Code: Select all
using System;
using System.Text.RegularExpressions;
struct info
{
public string output;
public Match header;
public Match title;
public string URL;
public void results()
{
Console.WriteLine("-=-RESULTS-=-");
Console.WriteLine("Website Page Title (title): {0}", title);
Console.WriteLine("Website header (h1): {0}", header);
}
public static Match find(string reg) {
Regex r = new Regex(reg);
Match m = r.Match(output);
return m;
}
}
class WebApp
{
public static void Main()
{
info web;
System.Console.Write("Enter a URL to analyze then press enter.\n e.g. http://www.alexgeek.co.uk \n >");
string input = System.Console.ReadLine();
if (input == null)
{
web.URL = "http://www.alexgeek.co.uk";
}
else
{
web.URL = input;
}
web.output = new System.Net.WebClient().DownloadString(web.URL);
web.header = web.find(@"<h1>(.)+</h1>");
web.results();
}
}
And the errors:
- Code: Select all
fileWrite.cs(19,27): error CS0120: An object reference is required for the
nonstatic field, method, or property 'info.output'
fileWrite.cs(7,19): (Location of symbol related to previous error)
fileWrite.cs(40,22): error CS0176: Static member 'info.find(string)' cannot be
accessed with an instance reference; qualify it with a type name instead
fileWrite.cs(17,25): (Location of symbol related to previous error)
I've not a clue what do! Please help