0
我試圖在https://www.americasarmy.com/soldier/1309069中獲取元素的值Neutralizations Deaths Ratio。
使用下面的代碼:如何從其他網站獲取html元素的值MVC
using (WebClient client = new WebClient())
{
try
{
client.DownloadString("https://www.americasarmy.com/soldier/1309069");
}
catch (WebException webex)
{
using (var streamReader = new StreamReader(webex.Response.GetResponseStream()))
{
ViewBag.htmlCode = streamReader.ReadToEnd();
}
}
}
如果妳看着上方,然後按F12鍵鏈接ü可以看到所有這些元素,但我所得到的,當我使用此代碼,這些elements,所以我想要的是讓所有的元素來獲得Neutralizations Deaths Ratio的價值。
您可以使用HtmlAgilityPack爲[解析HTML字符串(HTTP:/ /stackoverflow.com/questions/9355834/parsing-html-in-c-sharp-asp-net),然後以編程方式搜索元素。 – Jasen
可能想要讀取函數返回的內容:'var resource = client.DownloadString' –
@Jasen這不是問題,我想要的是從https://www.americasarmy.com/soldier/1309069獲取所有元素我使用的代碼不會像我說的那樣返回所有的元素。 – Ali