Google Spreadsheet XPATH: Cant extract element that have no data/value - xpath

from this link i want to get rank position sign, i get image links using this:
=IMPORTXML("https://int.soccerway.com/national/england/premier-league/20172018/regular-season/r41547/tables/","//table[#class='leaguetable sortable table detailed-table']//tr/td[#class='direction']/img/#src")
yes, i get img url.
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
but how to get <td class="direction"></td> that has no element inside?
some element have img tag like this:
<td class="direction"><img src="https://s1.swimg.net/gsmf/678/img/delta_plus.gif" width="7" height="4" title="Previous rank: 4" alt="Previous rank: 4"></td>
the other element has no img tag inside:
<td class="direction"></td>
how to get element that have no data inside so i can get the list like this:
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
what should i do? Thanks

You want to retrieve both <td class="direction"></td> and <td class="direction"><img ... /></td>. When td has no <img ... />, you want to put the empty row. If my understanding is correct, how about this modification? https://int.soccerway.com/national/england/premier-league/20172018/regular-season/r41547/tables/ is put in "A1".
Modified formula :
=IMPORTXML(A1,"//td[#class='direction' and not(*)] | //td[#class='direction']/img/#src")
//td[#class='direction' and not(*)] means that td is class with direction and without the child elements.
//td[#class='direction']/img/#src means that td has the child element of img, and retrieve #src.
By these, when td of #class='direction' has the child element of img, #src is retrieved. When td of #class='direction' has no the child elements, the empty is put.
Result :
Note :
You can also use =IMPORTXML(A1,"//table[#class='leaguetable sortable table detailed-table']//tr/td[#class='direction' and not(*)] | //table[#class='leaguetable sortable table detailed-table']//tr/td[#class='direction']/img/#src").
If I misunderstand your question, I'm sorry.

Related

XPATH that does extract style background color RGB value?

Can someone tell me an XPATH that does extract background color RGB values, or whole style, then I will remove unneeded data using Excel find/replace.
Been able to extract car color names using XPATH //div[#class='colorName']
<div class="colours" style="background-color: #040404; height: 30px; width: 130px; margin: 7px"></div>
<div class="colorName">Obsidian Black</div>
Source page: http://www.carwale.com/mercedesbenz-cars/e-class/e63amg-3049/
You can use the combination of substring-after() and substring-before():
substring-before(substring-after(//div[#class="colours"]/#style, "background-color: "), ";")
Works for me in the chrome console:
> $x('substring-before(substring-after(//div[#class="colours"]/#style, "background-color: "), ";")')
"#040404"

Trademark positioning in Outlook

I have a client that is nit picking the position of a trademark symbol and doesnt want to use the sup because it is too high.
So i have this
<table>
<tr>
<td class="mobilePadding mobileFontFix" bgcolor="#ffffff" style="background:#fff;padding:40px 20px 10px 40px;color: #636363;line-height: 22px;font-size: 24px;">
Some Test Before <span style="font-size: 14px;position: relative;bottom: 4px;">™</span> some Text after
</td>
</tr>
</table>
But of course Outlook doesn't support position:relative
Any other thoughts on how i can move the trademark up slightly in a way that outlook will render it?
Two suggestions I would have would be:
Use the <sup> tag, but add a <span> around the outside, with the <span> containing style="font-size:Xpx; line-height:Xpx;" , ensuring that "X" for the line-height and font-size are smaller than the rest of the of your styled text, this will bring it down lower in terms of height.
Replace the TM symbol with an image of the symbol, this may give you more flexibility with it's position by using padding or spacers.

carousel-slide-dimension on Jquery Cycle2 -fixed width/height

on this page it says you can set the width and height of each slide:
http://jquery.malsup.com/cycle2/demo/carousel.php
carousel-slide-dimension = The width (horz carousel) or height (vert carousel) of each slide. If this option is not set the value will be inferred from the first slide's dimensions.
but how do I exactly add it to the code? It's not clear:
<div class="slideshow"
data-cycle-fx=carousel
data-cycle-timeout=1000
>
<img src="http://malsup.github.com/images/beach1.jpg">
<img src="http://malsup.github.com/images/beach2.jpg">
...
<img src="http://malsup.github.com/images/beach9.jpg">
</div>
All the attributes with cycle2 are preceded by "data-cycle-" so for carousel-slide-dimension, you simply add that like so:
data-cycle-carousel-slide-dimension=300
in your slideshow div (and whatever dimension).
Hope this helps!

Find all elements that has a specified nested child

Hey, i've parsed html doc. need to find all element that has a specified child(can be not a direct child).
for ex:
<center>
<table>
...
<a />
</center>
find all "center" tags that has nested link
thanks!
Use:
//center[.//a]
This selects all center elements in the document that have an a descendent.
And this:
//center[.//*/a]
selects all center elements in the document that have an a descendent, which is not a child of this center element.
How about the following:
//center[element()//a]
This says to find all 'center' elements that contain any 'a' elements that
are descendents of 'center's direct element children.
Can't you use the descendant axis in the predicate?
//center[descendant::a]

Xpath - get only node content without other elements

I have an div elemet:
<div>
This is some text
<h1>This is a title</h1>
<div>Some other content</div>
</div>
What xpath expression should I use to only get the div content without his child elements
h1 and div
//div[not(h1)&not(div)]
Something like that? I cannot figure it out
To get the string value of div use:
string(/div)
This is the concatenation of all text nodes that are descendents of the (top) div element.
To select all text node descendents of div use:
/div//text()
To get only the text nodes that are direct children of div use:
/div/text()
Finally, get the first (and hopefully only) non-whitespace-only text node child of div:
/div/text()[normalize-space()][1]
What xpath expression should I use to
only get the div content without his
child elements h1 and div
This XPath expression:
/div/node()[not(self::h1|self::div)]
It selects every div root element's children except those h1 or div elements.
expression like ./text() will retrieve only the content of root element only.
Regards,
Nitin
You can use this XPath expression:
./div[1]/text()[1]
to test, I use this online tester : http://xpather.com/

Resources