Question Details

No question body available.

Tags

web-scraping xpath syntax extract xidel

Answers (2)

March 16, 2026 Score: 3 Rep: 67,659 Quality: Medium Completeness: 60%

In your first XPath //div[@id="buttonblock"]/div[a="Download"]/a/@href the predicate [a='Download'] is testing whether the div has an a child element that has a computed text value of Download, and then selects all of the a/@href (even if they don't have "Download").

In your second XPath //div[@id="buttonblock"]/div["Download"]/a/@href the predicate ['Download'] isn't doing what you might think it is. That string "Download" is "truthy" and will ensure that the predicate evaluates to true for any/all div. Basically, it's useless.

In your third XPath //div[@id="buttonblock"]/div[a="Download"]/@href you left out the step that had selected the a, so it's looking for @href on the div that has the a.

You could move the predicate from the div to the a to avoid repeating a in your XPath:

//div[@id="button
block"]/div/a[.="Download"]/@href
March 16, 2026 Score: 0 Rep: 165,761 Quality: Medium Completeness: 80%
div[a="Download"]/a/@href

For every

that has an element Download (with any attributes), return every attribute value.

Reading this it seems like you might only want the download URL and you might look for

div/a[.="Download"]/@href

That is, for every

, for every child whose text value is Download, return its @href attribute.

The difference between these two is if your input is



The first expression will match the first

because it has a "download" link, and return both URLs. The second expression will match specifically the Download element and return its URL. Neither will match the second URL.

In your examples:

  • div["Download"]/... returns a
    element whose text is "Download" (it would still probably work if there was only one link and nothing else with text).
  • div[a="Download"]/@href looks for the href attribute on the
    element itself, not the child element.