0

I wanna retrieve the parameters from certain URL, how could I do this with htmlagilitypack?

Example URL: https://stackoverflow.com/questions?page=4&sort=newest

I want to get the page number and the sort value...Is it possible to do that??

The codes for load HTML page:

public HtmlDocument ExtractHtml(string url)
{
    HtmlDocument doc = new HtmlWeb().Load(url);
    return doc; 
}
Community
  • 1
  • 1
erntay2
  • 140
  • 3
  • 16

1 Answers1

3

This has nothing to do with HtmlAgilityPick since the question isn't about parsing HTML but parsing URL from which you'll get the HTML. If I understand this correctly, URL in your code is just a string, so you can use HttpUtility.ParseQueryString() to parse it and get parameters you want :

var parameters = HttpUtility.ParseQueryString(new Uri(url).Query);
var pageParam = parameters.Get("page");
var sortParam = parameters.Get("sort");

dotnetfiddle demo

Related question : Get url parameters from a string in .NET

Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137