I'm getting some text from Safari in a column.

I used to use this script to add all text from this column in a list :

PS the class is class="sortable null"

tell application "Safari Technology Preview" to tell document 1 to tell (do JavaScript "
    [...new Set( document.getElementsByClassName('sortable null') )]
    .map( x => x.innerText.trim() );") ¬
    to set xID to every text

However, now, there is a another column which the same class class="sortable null"

So when I running my script, both text (column 1 and column 2) are add in the list .

e.g :

{"column1", "column2", "column1DATA", "column2DATA", "column1DATA", "column2DATA"}

I'm not sure how can I only get the text from the column 1 (and in a another not, remove the column 2

If I'm using this text for deleting the column, that will just delete both as they have the same name.

tell application "Safari Technology Preview" to ¬
    do JavaScript ¬
        "document.querySelectorAll(\"[class=\\\"sortable null\\\"]\").forEach(el => el.remove());" in current tab of window 1

Coming back to my list, I'm guessing that the only option is to created two new lists, one with the even items, one with the odd items and them just keep the 1 list, is that the only solution?

  • I'm trying to get only the text from the first raw (which is also called sortable null) or deleting the second class. I'm updating my question as it was unclear at the first place – Kevin Apr 15 at 13:57
  • As you've found out, class names are not unique to a particular HTML element. Therefore, you should consider identifying these elements some other way: if they have an id attribute, that will be unique; otherwise, read the CSS Selectors Reference that show you how to form a query to use with querySelector or querySelectorAll allowing you to isolate elements by any attribute (not just class or id); or by its relationship to other elements; and other properties as well. – CJK Apr 16 at 14:27

You must log in to answer this question.

Browse other questions tagged .