-3

Can I access the data of an HTML table using C#?
I have to get the innerText of a <td> from C# (I can't use anything else).
Is there a simply way? Maybe using Selenium or Coypu?

Igic
  • 45
  • 7
  • http://stackoverflow.com/questions/22950337/retrieve-data-from-html-table-in-c-sharp –  Jun 28 '16 at 13:26

2 Answers2

2

yes, using selenium

IList<IWebElement> TRCollection = driver.FindElement(By.Id("tableId")).FindElements(By.TagName("tr"));
IList<IWebElement> TDCollection;

foreach(IWebElement element in TRCollection )
{
//td list from each row
TDCollection = element.FindElements(By.TagName("td"));

string column1 = TDCollection[0].Text;
...
}
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
  • 1
    if you need only table data from html and not all the process to enter the website you better use like @Alex Turcan said the Html Agility Pack. selenium is more for browser automation. – Leon Barkan Jun 28 '16 at 13:33
  • Uhm, I'm writing an autmation module.. and I need to confront my value with the one on the web page. What do you think, should I use selenium or HtmlAgilityPack? – Igic Jun 28 '16 at 14:19
  • definitely selenium. – Leon Barkan Jun 28 '16 at 14:20
1

Html Agility Pack is what i use when i need any data from a webpage. It is convenient because you get a tree similar to an XmlDocument, making it easy to "walk the tree" or to perform any kind of queries.

Alex
  • 3,689
  • 1
  • 21
  • 32
  • Can you please be more specific? Do you have any example of "walking the tree". I'm not very familliar with HtmlAgilityPack ... – Igic Jun 28 '16 at 14:08
  • It is very simple and straight forward. You can use XPATH to get what you need. Here's is a link with a more specific implementation http://stackoverflow.com/questions/655603/html-agility-pack-parsing-tables – Alex Jun 28 '16 at 14:13