开发者

Get HTML table data

I have a HTML table (well I didn't make it but I am using it, just to clear that up) with开发者_JAVA技巧 many rows and a few columns.

I want to get some of the data into a string to use as a tooltip. The way I am doing it now is reading the contents of the HTML file as a string and using string manipulation to get the data I want.

This is probably a very bad idea, so I was wondering if there is any API I could use to read text from a specific row and column in a HTML file (like row 2 column 2). I would prefer not using an external .dll library file but I'll have to use it if there is no other way.

Any ideas?


HTML Agility Pack

There are some good examples of how to use the HTML Agility Pack.

Refer links posted by rtpHarry in this answer

An example from the codeplex site as to how you would fix all hrefs in an HTML file using the HTML agility pack:

 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
 }
 doc.Save("file.htm");


One of the way could be to use library such as Html Agility Pack to load the html document and then use DOM api or xpath to navigate to required node and get the content. This may get started you on agility pack: How to use HTML Agility pack

Lastly, if your html is xhtml (or in valid xml form) then you may use xml libraries available in .NET itself to do the manipulation.


Actually, I think the approach you're taken is a fine idea.

That's probably how I'd do it. There might be libraries to do it, but they'd just be doing the same thing.

It would be better to get the data from the source rather than parsing it from an HTML page. But if that's all you have, that's what you need to do.

Why do you think it's a bad idea?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜