C# - List all the links in a website.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Text.RegularExpressions;
namespace ProgrammingDotNet
{
class Program
{
public static void Main(string[] args)
{
StreamReader reader = null;
try
{
WebRequest request = WebRequest.Create("http://www.techexams.net/");
WebResponse response = request.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();
Regex regex = new Regex("href\\s*=\\s*\"([^\"]*)\"", RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(content);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1]);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Text.RegularExpressions;
namespace ProgrammingDotNet
{
class Program
{
public static void Main(string[] args)
{
StreamReader reader = null;
try
{
WebRequest request = WebRequest.Create("http://www.techexams.net/");
WebResponse response = request.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();
Regex regex = new Regex("href\\s*=\\s*\"([^\"]*)\"", RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(content);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1]);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
Console.ReadLine();
}
}
}
Comments
Post a Comment