Created
April 9, 2010 02:35
-
-
Save zachbonham/360821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net; | |
using System.Xml.Linq; | |
namespace getsmarx | |
{ | |
public static class StringExtensions | |
{ | |
public static string Right(this string source, int count) | |
{ | |
return source.Substring(source.Length - count); | |
} | |
public static string Left(this string source, int count) | |
{ | |
return source.Substring(0, count); | |
} | |
} | |
class Program | |
{ | |
static Random _random = new Random(); | |
static readonly int GUID_LENGTH = 36; | |
static void Main(string[] args) | |
{ | |
WebClient c = new WebClient(); | |
string data = c.DownloadString("http://annoysmarx.cloudapp.net/"); | |
XDocument x = XDocument.Parse(data); | |
XNamespace ns = "http://www.w3.org/1999/xhtml"; | |
var anchors = x.Descendants(ns + "a") | |
.Select(a => a.Attributes("href") | |
.FirstOrDefault().Value) | |
.ToList(); | |
var anchor = anchors[_random.Next(0, anchors.Count() - 1)]; | |
var id = anchor.Right(GUID_LENGTH); | |
var response = c.DownloadString(anchor); | |
Debug.Assert(response.Contains(id)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment