Last active
March 12, 2018 14:53
-
-
Save lothrop/531484cc0d0d53e5b926 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
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; | |
} |
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
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; | |
} | |
} |
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
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(); | |
} |
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
string html = await client.GetStringAsync().ConfigureAwait(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
client.GetStringAsync(); should probably be client.GetStringAsync(uri);