Post

Replies

Boosts

Views

Activity

How to extract value of HTML-attribute in Safari (desktop) using Xpath?
Quote from this question https://stackoverflow.com/questions/4531995/getting-attribute-using-xpath Given an XML structure like so: <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> How could I get the value of lang (where lang is eng in book title), for the first element? Answer: /*/book[1]/title/@lang . When I use this construct in Safari, the result is empty (it works in Chrome and Firefox). Is this broken in Safari? Are there workarounds that work with document.evaluate? I want/expect something like an array that I can use in AppleScript. (There is an xpath-workaround - suffixing the xpath with .map(link => link.href) but it doesn't work with document.evaluate) Update: it seems I am partially wrong - @/ does indeed work in simple examples. More details to reproduce my problem: On https://www.facebook.com/zuck/followers I want to extract the link to all the followers. The element I target looks like this: <a class="x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g xt0b8zv" href="https://www.facebook.com/profile.php?id=100065103331942" role="link" tabindex="0"> A simple xpath (I will optimise it later) that points to this element: //div/div[1]/div/div[3]/div/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div/div[3]/div/div[2]/div[1]/a As you can see the a has four attributes, class,, href, role and tabindex. If I add /@class at the end of my xpath it evaluates to class="x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g xt0b8zv" just as expected. Adding role or tabindex as the end also gives the expected result but if I try with href instead of class, I just get href (the actual string) as result. Or, it is even weirder and hard to describe in just text: Collapsed result Expanded result
2
0
469
Apr ’23