c# - downloading web pages html into html document -


i want html of web page. html there 2 elements who's xpath have want read. have little 0 knowledge on topic.

when searching keep seeing examples load url , put html string. believe since have 2 xpath's better download html of web page html document rather string or wrong?

using (webclient client = new webclient()) {     string s = client.downloadstring(url); } 

so how download html of webpage html document can search?

this how this.

  1. so first define url in string variable.
  2. then download string httpwebrequest class.
  3. i use htmlagilitypack, should include in project (using nugger example).
  4. create object of htmldocument, , load data object.
  5. now can navigate on htmldocument.

     string urladdress = "url.com";   httpwebrequest request = (httpwebrequest)webrequest.create(urladdress);  httpwebresponse response = (httpwebresponse)request.getresponse();  string data = "";  if (response.statuscode == httpstatuscode.ok)  {  stream receivestream = response.getresponsestream();  streamreader readstream = null;   if (response.characterset == null)  {      readstream = new streamreader(receivestream);  }  else  {      readstream = new streamreader(receivestream, encoding.getencoding(response.characterset));  }   data = readstream.readtoend();    response.close();  readstream.close(); }   htmldocument document2 = new htmlagilitypack.htmldocument();  document2.loadhtml(data); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -