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?
-
stackoverflow.com/questions/22950337/…user6522773– user65227732016-06-28 13:26:51 +00:00Commented Jun 28, 2016 at 13:26
Add a comment
|
2 Answers
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;
...
}
3 Comments
Leon Barkan
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.
Igic
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?
Leon Barkan
definitely selenium.
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
Igic
Can you please be more specific? Do you have any example of "walking the tree". I'm not very familliar with HtmlAgilityPack ...
Alex
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/…