Skip to content

Instantly share code, notes, and snippets.

@zachbonham
Created April 9, 2010 02:35
Show Gist options
  • Save zachbonham/360821 to your computer and use it in GitHub Desktop.
Save zachbonham/360821 to your computer and use it in GitHub Desktop.
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