wpf - What problems are about HttpAgilityPack -


here code html on website.

<span class="def">  make   <a class="query" title="clear" href="http://dictionary.cambridge.org/dictionary/british/clear"></a>   or   <a class="query" title="easy" href="http://dictionary.cambridge.org/dictionary/british/easy"></a>     <a class="query" title="understand" href="http://dictionary.cambridge.org/dictionary/british/understand"></a>     <a class="query" title="describing" href="http://dictionary.cambridge.org/dictionary/british/describe"></a>   or giving   <a class="query" title="information" href="http://dictionary.cambridge.org/dictionary/british/information"></a>   it:  

how that? want results:to make or or giving it

i have code of httpagilitypack.

string url = "http://dictionary.cambridge.org/dictionary/british/appeal";         htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument();         webrequest request = webrequest.create(url);         webresponse response = await request.getresponseasync();         streamreader stream = new streamreader(response.getresponsestream());         string content = await stream.readtoendasync();          list<string> list = new list<string>();          foreach (...)         {            ...         } 

i hope help.

private async void print_def(string uristring)     {         using (httpclient client = new httpclient())         {             //verify uri valid             uri outuri;             if(uri.trycreate(uristring,urikind.relativeorabsolute,out outuri))             {                 //try site                 httpresponsemessage response=new httpresponsemessage();                 try                 {                     response = await client.getasync(outuri);                 }                 catch (httprequestexception exc)                 {                     system.diagnostics.debug.writeline("error geting html site");                 }                 //check if site returned success code 200                 if (response.issuccessstatuscode)                 {                     string html = await response.content.readasstringasync();                     system.diagnostics.debug.writeline("succes");                     htmldocument htmldoc = new htmldocument();                     htmldoc.loadhtml(html);                      foreach (htmlnode defnode in htmldoc.documentnode.descendants("span").where(spannode => spannode.attributes.contains("class")&&spannode.attributes["class"].value.equals("def")))                     {                         system.diagnostics.debug.writeline(defnode.innertext.tostring());                         //put here whaterver want text                     }                 }             }         }     } 

you can copy paste function projekt , give pass url want scrape string. works me hope answers question.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -