Html Table to string

hello, is it possible to extract the table, and store it to a list from the following url? view-source:ΑΑΔΕ - Έλεγχος αποδείξεων

I have already tried the command getElementsByClassName (because the class i want to extract is "receipt" and its table contents) but it did not work no matter what.

Try this:

window.AppInventor.setWebViewString(document.getElementsByClassName('receipt')[0].innerHTML + document.getElementsByClassName('info')[0].innerHTML)

It maybe you need to check with the website owner that it is OK for you to scrape their data....

1 Like

Thank you very much for your fast response, i have one more question. How cai i extract the content of the cells (from the previously provided table), into a string using commas as seperators between each cell?

This just about does it, does not remove the <strong> tags from the first two cells....you should be able to remove that with some text manipulation....

var data = document.getElementsByClassName('info')[0].getElementsByTagName('td');
var arr = [];
for (var i = 0; i < data.length; i+=2) {
  var set = new Set([data[i].innerHTML, data[i + 1].innerHTML]);
  arr.push(Array.from(set));
}
window.AppInventor.setWebViewString(JSON.stringify(arr))

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.