xpathxpath-2.0xpath-1.0

XPath for extracting image scr with style attribute with the help of Screaming Frog


My goal is to extract image URLs together with style attribute (width and height) with the help of Screaming Frog.

<p style="text-align: center;"><img alt="Scary games are all about submerging into unknown territories" src="//cdn01.x-plarium.com/browser/content/blog/images/2022/scary-games-2.webp" style="width: 640px; height: 426px;"></p>

I am adding the following XPath for custom extraction - //img[contains(@style)]/@src But getting errors for this.

Will really appreciate any help.


Solution

  • Your XPath below contains an error

    //img[contains(@style)]/@src
    

    The contains functions expects two parameters. You have only passed one (@style). The parameters are both strings; if the second string is a substring of the first then the function returns true, otherwise it returns false.

    If you just want to check that the style attribute has some value (any value) then the following will work:

    //img[@style]/@src
    

    If you want to check that the style attribute contains some particular string (e.g. 'width') then you want something like this:

    //img[contains(@style, 'width')]/@src