-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?

1

2 Answers 2

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;
...
}
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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?
definitely selenium.
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.

2 Comments

Can you please be more specific? Do you have any example of "walking the tree". I'm not very familliar with HtmlAgilityPack ...
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 stackoverflow.com/questions/655603/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.