简体   繁体   English

52/5000如何通过c#获取html代码中的某个值

[英]52/5000 How to get a certain value in html code by c #

i want search spacial value in html code by webbrowser in c#.我想在 c# 中通过 webbrowser 在 html 代码中搜索空间值。 for example html code <span class="pulser " data-dollari="164.843956376000000" eq_toman="_XcUOV" pulser-change="_OiuVD" pre-dollari="164.964899983000000">$164.97</span> i need Getting the value "164.964899983000000" and another value html code.例如 html 代码<span class="pulser " data-dollari="164.843956376000000" eq_toman="_XcUOV" pulser-change="_OiuVD" pre-dollari="164.964899983000000">$164.97</span>需要价值 164.99 804.9904.904.904 <span class="pulser " data-dollari="164.843956376000000" eq_toman="_XcUOV" pulser-change="_OiuVD" pre-dollari="164.964899983000000">$164.97</span> 9061 " 和另一个值 html 代码。

If I understand you correctly, you want to get an element from a site and get its attribute values like 'pre-dollari'.如果我理解正确,您想从站点获取元素并获取其属性值,例如“pre-dollar”。

For c#, you can use ScrapySharp , it's a library where you can simulate a webbrowser and scrape its contents.对于 c#,您可以使用ScrapySharp ,它是一个库,您可以在其中模拟网络浏览器并抓取其内容。 You can use it alongside htmlAgilityPack to effectively traverse the elements.您可以将它与htmlAgilityPack一起使用以有效地遍历元素。

So for your case, it could look like this.所以对于你的情况,它可能看起来像这样。

// get your Url
Uri url = new Uri("Yoursite.com");
// open up the browser
ScrapingBrowser browser = new ScrapingBrowser();
// navigate to your page
WebPage page = browser.NavigateToPage(url, HttpVerb.Post, "", null);
// find your element, convert to a list and take the first result [0]
HtmlNode node2 = page.Find("span", By.Class("pulser")).ToList()[0];
// and now you can get the attribute by name and put it in a variable
string attributeValue = node2.GetAttributeValue("pre-dollari", "not found"); 
// attributeValue = 164.964899983000000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM