Skip to content

Instantly share code, notes, and snippets.

@lothrop
Last active March 12, 2018 14:53
Show Gist options
  • Save lothrop/531484cc0d0d53e5b926 to your computer and use it in GitHub Desktop.
Save lothrop/531484cc0d0d53e5b926 to your computer and use it in GitHub Desktop.
public async Task<bool> DoesWebContentMatchPatternAsync(Uri uri, Regex pattern)
{
HttpClient client = new HttpClient();
string html = await client.GetStringAsync();
bool matches = pattern.Matches(html);
return matches;
}
public async Task<bool> DoesWebContentMatchPatternAsync(Uri uri, Regex pattern)
{
try
{
HttpClient client = new HttpClient();
string html = await client.GetStringAsync();
bool matches = pattern.Matches(html);
return matches;
}
catch (Exception)
{
return false;
}
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri uriToTest = new Uri(uriBox.Text);
Regex expressionToTest = new Regex(@"\b(spoon|knife|fork)\b");
bool matches = await DoesWebContentMatchPatternAsync(uriToTest, expressionToTest);
resultBox.Text = matches.ToString();
}
string html = await client.GetStringAsync().ConfigureAwait(false);
@Danghor
Copy link

Danghor commented Feb 7, 2018

client.GetStringAsync(); should probably be client.GetStringAsync(uri);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment