json - vb net + getting content from a div with htmlagilitypack -
flow:
1. (ok) download json
2. (ok) parse value json object contains html
3. (not ok) display values inside div.countries
code:
dim webclient new system.net.webclient dim result string = webclient.downloadstring("http://example.com/countries.json") dim values jobject = jobject.parse(result) dim finalhtml string = values.getvalue("countries_html")
basically finalhtml variable looks this:
<div class="country_name">usa</div> <div class="country_name">ireland</div> <div class="country_name">australia</div>
im stuck , dont know how move on. need go on div.country_name , inner_text of it. hope make sense.
since finalhtml
string contain target div elements, can load string htmldocument
object , use bit of linq project divs collection -ienumerable
, list<t>
, or whatever suitable need- of innertext strings :
.... dim finalhtml string = values.getvalue("countries_html") dim doc = new htmldocument() doc.loadhtml(finalhtml) dim countries = doc.documentnode.elements("div").select(function(o) o.innertext.trim()) 'print result comma separated text console: console.writeline(string.join(",", countries))
output :
usa,ireland,australia
Comments
Post a Comment