Class | Scrubyt::XPathUtils |
In: |
lib/scrubyt/utils/xpathutils.rb
|
Parent: | Object |
Find an image based on the src of the example
parameters
doc - The containing document
example - The value of the src attribute of the img tag This is convenient, since if the users rigth-clicks an image and copies image location, this string will be copied to the clipboard and thus can be easily pasted as an examle
index - there might be more images with the same src on the page - most typically the user will need the 0th - but if this is not the case, there is the possibility to override this
Used when automatically looking up href attributes (for detail or next links) If the detail pattern did not extract a link, we first look up it‘s children - and if we don‘t find a link, traverse up
Generate XPath for the given node
parameters
node - The node we are looking up the XPath for
stopnode - The Xpath generation is stopped and the XPath that was generated so far is returned if this node is reached.
write_indices - whether the index inside the parent shuold be added, as in html[1]/body[1]/table[2]/tr[1]/td[8]
Generate a generalized XPath (i.e. without indices) of the node, relatively to the given relative_root.
For example if the elem‘s absolute XPath is /a[1]/b[3]/c[5], and the relative root‘s Xpath is a[1]/b[3], the result of the function will be /c.
Generate an XPath of the node with indices, relatively to the given relative_root.
For example if the elem‘s absolute XPath is /a/b/c, and the relative root‘s Xpath is a/b, the result of the function will be /c.
Generalre relative XPath from two XPaths: a parent one, (which points higher in the tree), and a child one. The result of the method is the relative XPath of the node pointed to by the second XPath to the node pointed to by the firs XPath.