0

SO contributors. I am fully aware of the following question How to obtain href values from a div using xpath?, which basically deals with one part of my problem yet for some reason the solution posted there does not work in my case, so I would kindly ask for help in resolving two related issues. In the example below, I would like to get the href value of the "more" hyperlink (http://www.thestraddler.com/201715/piece2.php), which is under the div tag with content class.

<div class="content">
            
<h3><a href="http://www.3quarksdaily.com/3quarksdaily/2016/12/against-the-renting-of-persons-a-conversation-with-david-ellerman.html">Against the Renting of Persons: A conversation with David Ellerman</a></h3>
   
<a href="http://www.thestraddler.com/201715/piece2-print.php#footnote1">[1]</a>                                              
</p>
<p>More <a href="http://www.thestraddler.com/201715/piece2.php">here</a>.</p>     
</div>

In theory I should be able to extract the links under a div tag with
xidel website -e //div[@class="content"]//a/@href but for some reason it does not work. How can I resolve this and (2nd part) how can I extract the href value of only the "here" hyperlink?
user3612816
  • 325
  • 2
  • 11
  • 1
    Your HTML is very broken... no closing , and no opening

    – Boy Sep 14 '17 at 12:48
  • 1
    just try`//div[@class="content"]//a[text()='here']/@href`...but HTML s/b well-formed as @Borna said... – Cylian Sep 14 '17 at 12:49
  • Thanks, but it still doesn't work...I have fixed the HTML and I have also tried just //a/@href to make sure all links can be extracted, but when I add [@class="content"] or [text()='here'] I get nothing. – user3612816 Sep 14 '17 at 13:09
  • Be sure to use the right quoting depending on your operating system. I'm using Windows, so for me it would be: `xidel "website" -e "//div[@class='content']//a[text()='here']/@href"`. On Linux I believe it's the other way around. – Reino Sep 17 '17 at 09:54
  • Fantastic, the outside double quotes and inner single ones solved the problem (I am also using Windows). Thank you. – user3612816 Sep 22 '17 at 08:20

0 Answers0