Xpath - choose A if B is 0 else choose B - xpath

I'm trying to gather some informations from an estatepage and i've run into this logic problem before and now i'm asking for your help.
basicly it's there are two different ways the table with info i'm looking at
<table>
<tr>
<th>Bolig areal</th> (estate size)
<td>0 m</td>
</tr>
<tr>
<th>Grund areal</th> (ground size)
<td>5000 m</td>
</tr>
</table>
and
<table>
<tr>
<th>Bolig areal</th> (estate size)
<td>123 m</td>
</tr>
<tr>
<th>Grund areal</th> (ground size)
<td>5000 m</td>
</tr>
</table>
I want to get the 'bolig areal'(estate size). But if 'bolig areal' is 0 m, then take Grund areal(ground size)
I'm currently stuck on an Xpath expression like:
//div[#class='description-element description-info shadow']//th[contains(.,'Grund areal') or contains(.,'Bolig areal')]/following-sibling::td/text()[not(contains(.,'0 m'))]
Where I select both the <th>, selects the following <td>/text, where the text is != 0m.
Which selects the Ground area.
How do I add the "if 'Bolig areal' is different from 0 m pick 'Bolig areal', otherwise use 'Ground areal'
solution:
".//tr[th = 'Bolig areal' and td != '0 m' or th = 'Grund areal' and not(ancestor::table/tr[th = 'Bolig areal' and td != '0 m'])]/td/text()"

try this:
//tr[th = 'Bolig areal' and td != '0 m' or th = 'Grund areal' and not(ancestor::table/tr[th = 'Bolig areal' and td != '0 m'])]/td
This selects the tr that has either th = 'Bolig areal' and td != '0 m' or the tr that has th = 'Grund areal' if the first expression th = 'Bolig areal' and td != '0 m' is not true for the current table. From that selected tr the td is selected.

What about:
//table[tr[th="Bolig areal"][td != "0 m"]]/tr[th="Bolig areal"]/td/text()
|
//table[tr[th="Bolig areal"][td = "0 m"]]/tr[th="Grund areal"]/td/text()
This is essentially a translation of:
if a table contains a row with a "Bolig areal" th that has a value (td) different from "0 m", pick that value (td/text())
alternatively (| operator), if the "Bolig areal" value is "0 m", select the value from the row with header "Grund areal"
You could use contains(th, "Bolig areal") instead of th="Bolig areal"
Example Python session with lxml (libxml2):
In [1]: import lxml.html
In [2]: doc1 = lxml.html.fromstring("""<table>
...: <tr>
...: <th>Bolig areal</th> (estate size)
...: <td>0 m</td>
...: </tr>
...: <tr>
...: <th>Grund areal</th> (ground size)
...: <td>5000 m</td>
...: </tr>
...: </table>""")
In [3]: doc2 = lxml.html.fromstring("""<table>
...: <tr>
...: <th>Bolig areal</th> (estate size)
...: <td>123 m</td>
...: </tr>
...: <tr>
...: <th>Grund areal</th> (ground size)
...: <td>5000 m</td>
...: </tr>
...: </table>""")
In [4]: xp = lxml.etree.XPath("""//table[tr[th="Bolig areal"][td != "0 m"]]/tr[th="Bolig areal"]/td/text()
...: |
...: //table[tr[th="Bolig areal"][td = "0 m"]]/tr[th="Grund areal"]/td/text()""")
In [5]: xp(doc1)
Out[5]: ['5000 m']
In [6]: xp(doc2)
Out[6]: ['123 m']
In [7]:

You want the first th that is not followed by 0 m, then extract the first following td:
//th[(.='Bolig areal' and following-sibling::td!='0 m') or (.='Grund areal' and ../..//th[.='Bolig areal']/following-sibling::td='0 m')]/following-sibling::td[1]

Related

The html file restored after deleting in windows looks different. How to restore the previous format?

I deleted my windows folder because of my inattention. I had important html files there that I didn't have time to push to the repository.
So I ran popular software to restore files (like CCleaner or Disk Drill), but the file I care about the most always looks the same (as in the photo below, this is the appearance after its restoration).
/#˙/s• ˙/ro˙Đ#„„9i·•#˙/uâđ/yTOŰńfő #qvsđls˙/˙}
ń/.Ń5xppk zĐ8 qT xp 3p€z0}5»PVq Đ*‘‘37wĐbt 0Đ»~0U/-0 Nwp cmŇ-lń| P±d‹°t±3'đ EPundĐŽ™
ż0o3?l˙}±=?Ueµ??“í?lĐ“s·oµ?5 1 7p˝So0'ń4q5p5r8t5?Ů5˙´˙´ ]d2 5w5Ż5#˙5s5• 55peúođŁsđµ˙´˙´˙´:ď:s5u5ś|5˙´ń©îc2Ť˙´q)tp,ŃR˙´4t ˙4_¸˙4g ˙ő4ńa´‘1Ó;´Q6?1ý?1e5?1´?1?1_“?1?1»g?1cspż0AÓ#}´q0ń0Řp´ę9ô0˙0˙0˙0˙0á– { ´˙0˙ó0• ˙0˙0˙0P‹˙0±QźŐaffffc ű0}y´`´pM7_.^.oµ p _ k z f 8 q x p3 Hz g 5€ c - 0 SŘ ** € ř :h 0 dcQ#“×  ŘP&ˇŁ& : 2 A 4  > â
'  Y
  F —Č! łm
‚#q Éá" k <3 Ä ™ 9 ˛dF©: żc{Gé  M i Ýr oD s€f t€tWQ€ n d€w€
-P S e€t‚
g€y n€;čÖ ŁH5W ekodt·$/ "D€0b u€µ€ë8p1÷ zH „ ¦S 7 E€Gp€r a€FiQ€n €Ot€r€e€X €Úo rU€p€
c€ça€)eE„t€- m€cck€‡x.€k€2Aa[Ŕ_‚,#Ĺ%O#eŁŔG%F l#g#Ň:Ŕ 4 AI#A9˘vBe T#uŔ©Á$d Á fŔl#Şe |i#eŔo#Z¶eŔZÁ4eŔGA'\ŔŞh#2lŔ\#oŔ
]Á4n#:ÁÉjsÄNh#KsŔH\Ŕi b Á CUAA.e .UŔpŔ2 Ân# P 2 9Ä˝sŔ…S+Á»Á˝h Ž;Ä˝?Î&$˙˝ { Ń˝żĎ˝EŐ˝E&˙˝` t &ľi 0˙^?h-h÷^ňŕ^"L mS PbCT ×!>ˇ]eas`s Aĺ`®f <˙^ď^tâeŕ>Şu`Icŕa 
e`J5aA_  w
ˇcb Ę3 l8 Gb a!˘® `!…cow`[t Ş `Fx` 0j H¨ Nŕ
w [c [!Xc+ â! l
rD '` Eŕ.dŰ  áws`ˇaFŕ aëˇaTcäu"áZcŻcec%aco``aŕ_·ˇ+'?%p˘m!xd˘?-ql1 7 6l 4B·#Sákál <äl~á˙l÷˙ËáĐńlżđË%ől%?˙lâ&˙ˤd–˙Ë- ×?Ő!Ő÷l¬ělC
±/}QYC%*ńW‘;Ń' Őp2a0"kĐ&g0 ×S]etUńł[pĐ[rÝhŃ%uf8˛4˙5ŞeĐ20˛?SPa0ÚF’.C”2Ó=6ź6k?2˙ceP.lp`‘a˙2q˙clóF?2“j?2?2ľlpÓ>_5Ń?2cPÚp0Bl°>sh6h2WŇnq1ń1čŔ=ô1Ęń˙1 ˙—12˙—˙—ű—‹ !Pś r˙ř—˙1ó—• ˙1˙—0ý˙1o°!rw&—u‡˙1'źś˙1źśc ű1ő Ľ“™  Ş pýCp _/12_/_/_/o_e[e˘P# ńqĺpP>uPU%˙†˛¶—{§P#~˙s• 0u÷±8¶ođ®»»S<űPu¶”pPő¶¶¶_¶¶q¶˙†˙†ep»yop†˙†·ŮŔF0MqsűrS·cp4··ż…·ďS·Ń”QˇtpV±L·ď14?y·1qdń/q0qâ?t0<Ď&000MpL2 ˙ć őć ý·#0s0• 00ď00Ň_·˙ćĐźëźS.0p0$µ ö L S P : T h e 8s y n c$e s i oQ D f r \pT a >k
g bs t t - mT i 2r Ns f 2. v p 9Q
i d Fo x5 .e Qs -Ys  _ 8 w k {b 3 )8 b q- 0 s/?dU w 7t ­ xE 0
- #N w c ›l lQ 1n g h nE _l€6r '€n ´ E€Ed€‰vF€U €#n€c€rĹ€u€p \€–é,\ wa‚}1
şe€pt„9…§… \€FŞo€’a€s€(t€Zi€#g€)Ľp‚(vë€xr€6l€>dŁę.€/p€» €1-ë€1 7 6 4€ü €8eh ** Ŕ#h„ Öá&“×€†Ř&€ˇŁ& € Ť ‚Ä Ŕ h Ŕ#Á D
 # E –Ŕ F#Ă! #ł #E Éá"Ŕ<3 ÄH E& A #˛d F©:żc{Gjé€/M#JcÂLEť-¬ WŔÁyoŔ•s#„
SJZSĸ;čÖ ŁH5Wekodtw/ D#b u#™ë#8p1÷ = ¬ ° SÉŮC#*e#‘íAĚCŔuÁeŔkÁ‹ĂŮ{˙×ÁnŔ“Cîß×áS`aŕPF`r C‡ŕkˇ#|= 0 /m˙dd+_dĄidío-Ńqd6 2$dsábácĘđ€UAäc$â˙c˙c#aińcŹ ! l ţrčc%őc%˙c˙c ‚?e&˙c?m#;% ëcő༓™ #‰a‘"ţ •żĘĄżĘˇ_˝Ę…ŤWâÖá<á= ŠBä=DĽa'˙ˇ˙ˇ :ń=«đˇż%ő=%˙=˙=˙ ˙Pżý|źUźUŃ˙PőPđPëU!ŃuppSrňPu†…Úrđ ez‡a0V±z•‡o0OopŠt "eLQ‡y‡, «pSyO*ePap -“
FĐu±sň“4 ]ŃI‘`Ń{c
T­u0‘drf°ęle#qi±yq_Ő1`oĐe0da°?†»?†=Nh°[Ń1†iđ“_1Ó3QO PO9[^ń0pń/q0Pp0Cńt0š<)0˛†°  súń0#0s• 0ű2oR!ß+ß+Ń+0O0†YźOg {Ţűp0˙· !‘ ©0»0˙·.đŹ‘¦±¬t¶˙p·¶¶ß1ą¶¶qŻ¶WĹ?„?0eP2lP°ű¶¶cPŚ¶Ý2?„׶ű‰?„c:pPB“/}¶P#q4ueDô4RZ˙4¶ł¶˙4˙4{¶e ţ#˙4ó4• ˙4˙4˙4˙PZ¶±ĐU0˙4˙4˙4˙4Ľc eye¶ŃZeЬćo2$¶c ěěńdîwr[4˙ę0r^˙´˙´˙›ëż0ż0ż0?ç—ä˙´’g0µ t i n g s y pc p r o v i d e X\ lŃ <c a s DÄÄ. Šp b¶e 6 2 4 i ** Ř Eh  Z)“ ×  Ř&ˇŁ& B ˘ 
'  :
 D F w ! E X rm #q p Éá"€5 < 3 ćL
˛d F©:żc{TGé cM€’c‚—sE€‘f€Ą- W€ n€ťo w€©- SŠ™S„˛;čÖ ŁH5Wekodt·$/ D€0b u€áő Ľ“™ • \ }Ťp€Ýc kU€g€s€Ra€eĐ - mŽ_.#-Az‚l#
t _ 8Ŕ‚eŔy b 3#5Š8ŔbÂ- 0FµP€[ ÁsÁuđ#S2FÄudÓ˙u×u“ô! AgłČuEŐuE&ë˙uBHtB{g#yCĎ˙uEËuë8p1÷b #t € ÉE µŔťp#"r#wÁ"oŔđ* ŔťtŔrByd h f# rŔ‚k[ŕW1A, eO`e« bˇLi n€plŕĄaŚ:ŕ4 ˇI «!W!Ťc T u"VeŕLáf`l e]ŕi`‰ááeŕ‹oU e`^a`
\`hŐ l`\ŕoŕ![»ˇšaeŕ ĺ4Ąśhŕű!aˇ›i`Zá#8çcńh2 9ä^yá\á]h Gä]DW.Ď˙˙ •ń ď]%˙ő]%˙]"'˙ŁĹe=˙]W?˘ă.÷]öŕ]L lSâ ⌠T ˇ=ˇ\#ő!e`#s`qă_˙]3źŞe Am Id aŕ Zx"hn`ăXs>˘ W ˇżaX ŕ¤i hQ`^0 xŕF0j Ń ° N Qw #ěVl áV `a`ydâ^r '` Eë"!ĘsfF ˇµ!Şn cŕ rŕ u `úp`Ŕs˘%c€ź]4ż‚ż‚ó"ß…Ó…?6 Ŕ 1 7 6Ô‚Uń5q6 Ht6\l6˙‚˙‚ 5[2 ˙‚đ„ó‚Ăe#˙6ó‚• 6˙‚6Ż˙‚q 6˙‚ođ]t°$_ź‡™O•6ue°|6CŐAeP$tĐ$C01$˙±WQ s6˙dź…•‘…˙5w±˙5‡w0‡qaS‹đ_±1F0 r C”2˝łŤ=6ź6?2˙ce6ölđ2ŃŻa’‘ń˙c3Gż?2“jß±?2?2?2o¸m?2 đ1ő´lq1ń1đŐŔ­Iô1T˙1˙1˙1Ł˙1h Ź˙´#˙˙1ó1• ˙1˙1p˙1˙1ű˙1˙´opR˙1źąśű1=ů´tĐ—˙´÷‚˙´t Ý_/e`_/¶b°hU/y…¶p qńqÔJůôőí˙P˙˙˙˙č «˙P#˙ó˙• ˙˙˙ ˙˙˙}˙dĐ˙˙óÓy¶÷đPUS¶n0{ł¶QwQQ1iđV"‡dŻŮ"˙·ÁF°Ma2ţńSř·Tµ e v i c pT r u s t Xd : # f a l De F Śl \ oT n c r uQ „p \ Fh lU Z\ Šo *m bnT g6e ¦tsÄ y ‚c h ‚Öâ\ 3i b'Ša…. —p p ‰
l=e 2 9 0 S ** h Kh{1“ ×  Ř&ˇŁ& B ˘€ €€
‚ U€
„€ # ! €
ł,‚
#…8 Éá"€5<3 Ä …L ! €˛ dF©:żc{¨Gé _M€oc‚śŠs€‹f€~- W‚yŠd€w€Ż- S€°jt€i€źg€–; čÖŁH€5Wekodt·$¨/ D#bŔ€g€N€ë8p1÷ €B( ö SL#S şPÂ…T#oÁbĹr Ŕ'şeŔ s#,Á‡AŽo#3Ş ŔnaŔpkŔgŔGv- Á‡K<. wÂp#mDe xŤ#<e#<Ĺ_ 8 ‚kŔ‘b 3 dŔbŔŹÁ- 0 UŔn#eŔ #
iŐŔh#0#0ŔÉ ¨ -#NBX Ŕ)ëA»CšgŔhŔ AÁ˝r 'Ŕ7 E#"~d#BI;˙ĆÍĆE×ÁĆoÝÄ%sŔ5GE^pÂŚAđŞdŔr#Ńl#3c#.Ăí_ql1 7 6Ä 4"Yo sákál LälĎ˙l˙láqńlĂďl%˙ől%˙lb&˙l˙l?v)źVS$ź÷l°ělC eŰ`9!˛Cŕ:á«eŕAáEĺălp c ˙k!Š˙k×a
ýkáÂSbRn#˘ˇ|ZC aŕb#|=`lx˙` kmd˙Çă1%_ddGdŁjqd6 2$di«ábácđ€ÂMäc]˙c˙Đ€Ż ńcŹ !ń Ů rčĐ%őc%×˙c˙1ROoĐTsShînđ hQ…rP+ź6ź‘‚˙1qhőĽ“™´ { \C_e§P012_et _/eR˙_e_eYe˘P# rvqńĺń‡Nôd“˙P‡‡ p2 ‡ ę s‡«˙P#˙s‡˙• ˙‡_Đs_Y˙g˙Ś˙Pc ˙Pu‡WđPU!‘§pr˛imn0z…r!ó~fýprpQĄ""qL«‡Q8P‡b01e01X0 ,Pµ
O*eWP41“
FP®aĐ°sőň“4ŇI…—Ń{˙·k˙·˙·e°ša°˙·a˙ň•ń±YUQ˙·•Wš­O POő·éů·Ot0xî6˙·˙·˛O˙·g0¸0w0’ BH¨| Yäpp ×ő·• 0˙0Đ#ßJ00˙·p“ĐßźĽTU#0u0ňp0˙·ßQ·3Ŕ˙·0ÓytźRP(îoŢs01v30“¸‘)e.µ"_p^w 5ŐĐ`102P7x0ŤÖy20ż·tp ·ż·ŃŤ3~ P…dP3~ep4ż·ŐŔ…‰1l˙±±h1ż·ż·ťż·źż·ó•5˙5 ą·ËôĄů·Pt6#6˙f˙fýf1µ#  :   FA 8ż!  łh##6 “×’BH ¨| Yp ×<3 Ä  PhVr l˛d F©:żc{ Gé M i c r o s f t - WQ n d w -P S e tg
y n 3;čÖ ŁH5W ekodt7I/ D ab u g ë8p1÷ z ¬ L€8S P : C€Te a€F˘e€o l€ e€EEMo€J p€cÔ k€g€)s€- m€_‹t. w‚i3 2€e bÔ v€e€h€}"_€-w 5€,1 ‚h€t x y€+˘w€- 0‚IS€Şa€F€r€Jh€=Şn€de€ť=€x€Ş0ŠF€2l€" €Şn€c‚e€a€_Z\Ŕ
h#Á6\BfaďÂ.ÁÁÉbsŔ!ÁbEj\ŔCoÂ#l#Q
pKBÁ9dŔr o.UŔpŔ) ŔiŔ=euŔe6ŔF4ĄŔ#5 ** čU  QDˇdD«€t Ř&ˇŁ& D
{ Ä D Ŕ Ŕc#Á
 ŃÇ‹„ !# r€»Ŕ€ #EŐÇE& ˙Ç=IZSÄd˙Ç% ëcő Ľ“™ #%  0ő'ŕ a 2ż^á{ż^c˝^ă+ uá;á<ĺŕ=Rä<ŹŕŁ’˙<Ŕ?÷ ;˙<é §đ %ő<%˙˙<bc˙ ˇ^˙ ?Ş-Ş÷ ®”€fĄAˇ†pŕlrŕŚçž#ťr"Łd ľfbŠ˙ˇ)ż?C=C, µĺO Re *áŻi jn Ůl`g “aą4ş ˇI ˇż!’c ŞT u`t`dâ«ţf`Ł™˙¦˙¦c7ĺ¦ĺĽýˇ iŕżá«ŁŰă)ˇńť 2 9 0Â`c Wŕ|á_á`pŕ`Sä`ÂlwA˘ó˙` ˙ť ÍŔđPó€˙€0ó€• 0˙€đ0oýqsđ˙€˙€˙€ź…ź…·ł0ő€üp0ů€TPyŰńgő #qwsvó€ß0u0.(oŇr0)p ń hp€±zlp 1‚ 0±”eUđ” đi:hP20«[0P-0 N°jwp cr/l‘ [Q†dPwQ5' t Eđwdđ‘9_2oű05ß…l°Ń?ß…uIUoß…ß…“ß…lĐ“s=tĐ8ß6 Ŕ1 7 6 ó…ro+q6ń6(đ6Tô6Ä~B˙6˙…2†˙…˙…ű6Éýg#˙6ó6• ˙6˙6˙P˙6˙6‘ őU˙…źĽźĽŮźŠc ˙6ő6¶ü6˙·Ýq¬cR˙·Q)tP,QTÝ˙·t4ó·6e°c6{ź¸±şyIź¸ź¸70ýiiň41uź¸Ń`eó+ß±ąż2ź/ź/oÇź¸×ż2Vż2cpp°BSBŻ›¸9ń1q2ř#±Ut2ü
2¸ł¸22{2ú•¸#2s2• 2ż22ęS2ęop’ßiiÓM{2y¸z‚ɸß/Wˇ_feîµ r e p . c h x a °p _ hw 5 n 1 ¨2 t dy św y -( 0 k Ľg eř ** € Vh >ÓdB“×  ŘP&ˇŁ& : 2 A 4  "
'  ‚:
  F ż ! E sm #q’BH¨€| Yp ×<3 x‘™ O ˛dF©:ż c{Gé M i€}r o Šs€f€|- W€ (n d€w€
- ŞS€„t€i€Źg€y€c ;čÖ ŁH5Wekodt·$/ DA€0b u g ť… ćˇ–©ˇ‚X źŔUB;Ń`z¸p °˙˙d  A˙˙/€F€!€=€jD C€_l l€,c‚]o€ZI€j
ř #
AA
A[D
B
u#
t
€l V€`hwLFt#‹eÜ mŔ#… :Â…Á‡Ę€"Wćś‹˙‡×‡±! AyłÇ‡ĂEŃ‡Ä E&˙‡;Ŕ?˙‡s#ÚSšË‡ë8°p1÷ŔpŔ[ž ŰŞSŔčnŔ° Ŕ{p#"ZrŔčtŔiÁ{ ŔŻtŔr#€eŔ~ fŃ# r  ~a`äy5¤t - 9-b. uë>.
p ?‰/‰,«`%O`eŕ‘aćS*FŕUa `s€ ´4 ˇI ácv`ęc T u"!€MŐ`aŕs`F`!^Őa!nŕc˘e káśZ\ h ˇb\ oµŕm n aeŕ«!'ás¤*h sŕÂ\ i b áăۡ!eb©á! bá# 2 9 ä¦ á`áa° Xyäa`ľ˙a˙ĄáŞńĄS˙đa%őĄ%˙ab'˙Ą˙ĄŢc? h2ĺF÷a#˙aŕ öa a]d`Qĺa7›?V­'V8?V"[f Ol Qje€Űi Fe áueí`ro ?Vg"Q?V?V7Qń+iq*ń*ŘH Yô*Ŕż˙* > ˙}1+˙}Ác˙} őő}y˙*#˙*ó}• ×˙*˙}R<oBtPV˙}?yU&˙}ź‚źźc «˙*ő[fđ*C…ER!¶NP
ńGf°Gł3 ň ő]| üX-0-qMqx_`‚n˛S Y NĐ} O P E R €A T I O0¨F LĐ GP=W˝mYqTQ2V °Lşx0 0: ßVż+eĐ-¶l°*–a˛eÓVcpZopYdP0óT\°l­upjŐWegZ>e0?ů­_X5 >7p­ˇ‰đśń,q-p Zt-˝dD«ź-˛«--{«‰ó- q‰• --űđXođ!ß„-«2Ź°°-u- P%ęS0%PŇ'Tr˘Ńłő‘ es°sŠ‰pĆoŃ‹Q(‰tpw}‰curUl#gĐŐ~_Îhűz]Î °qż“’±ń­ëż/Q0 pD Đ3±13«u Đa+d0.ęeĐ\' P7±žęsđ inß_PQ•ęupp/sr˙Šß_÷3ŹńŠo5•‘÷©•Rp o Q•dprĐŃ7±”7 ´ 1đ66pD7oq6•ń60đ6[ô6űy˙6ëdâ đß2 dwdúÍd#˙6ó6• ˙6˙6đ˙6˙61N˙6˙6ożi°!çS3˙6ő6şpdZLĐ6SĐ]ńZC°e0$‘3|චo n p# a c k Pg# e s t HtA H- m i dr śs f d. wQ Ln d <w ¬.Q >a l i –g- "h ra ®p "_ >w 5 61 h 2 ‚x y B‚w
- 0 : "SCn F Sr ZC 'aK‹= #xU 0
F l E 1n c9e u‘ ąp \…\ ˝˘aÉn ge …VtĹWy€5c€#oU€e€l€%c€#l«€"‘p‚(v€d€<Vr°™p€Ž „šee€6€Ť4 Ş- S0 ** ř \h €
LzD“ ×  Ř&ˇŁ& B€ ˘€ €€
‚ U€
€_Ŕ€^ ™ !# r, #E’B H¨| YpŔ×<3 DÄG& Â€˛dF©€:żc{Gé€1MŔJcBME‘- WoŔG‘Ŕ;ŔRtŔeC‘S#‡nŔd;čÖ ŁH5Wekodtw/ D#
b#g€NőĽ“™ €J ~DöŔcÁlB5oÁÂN W#ĄÁ{Á} N]Ä}â†ô˙}×}µ! ˇ7ţłč>%ő>%˙>˙>¨q˙>?H+Hë>ë8p1÷ > ˘€hëĺ
ápŕCrŕ~!ă˘#ˇrŕeŕť fO˘Ś˙Ą˙Ą˙Ąn óĄ,«`…ĄO`Veŕ+a ęi`nŔxl áOáŞt4 ˇIŕa_!–cµ`T u`!ĽdâŻ~f`Łť˙ŞĄ»˙ŞăŞh«ŕá(\bťb Ąsd{Ł+ˇńˇ2 9 0_Âbˇ¶ áaáb ŕb^ńäbwE˙ˇ˙ˇ žńˇćżŕbŔ« ±čb%ńbpx %˙b 0oĺ 0o Jt ˙ˇŁ)˙ˇ·? # ÷b¬p1ń/e6q«_ußcđoĐUd0
m\đ±tu°35eżr}:‘v?ůU!(0€4 7 6 )Đ#VS,bHT&.Đx­0 !°#701FĐ 1 3 4 8 `B E Ađ ń1(»
ł‹eĐ30đşFp7U±D¨ Rđtr°jHp(P)P9qCdŞ Ń
dđ8˛8rŞ4P FpŤDP 4 şC27lP±Q0xP<h: [0A méđ=t Ő>AĐ
1q<jt04]
2px–hq1ő1_ô1ů˙1k˙‚˙‚ 12 ˙‚9ö‚Ăc˙1 ˙ń1• ˙1˙‚2˙1ô‘RçńôAĐc ˙1ý«˙1Ż%‘‡˙1uc°đ1CPÚE˛SNP
Qf“gÚ poĐ0ń©c“Y¨ b°"oĐłsVrP2»Ą-P2oPŞau„sđ%gĐŞÓ¸-Ż’q!‘'Ń-x0"-Q6rRlnR
S Y N°&O Pđ/‚R0T I O0¨F LĐ Gđ=đ1_łq'ѱQ1 đ+xWP.Ń1±,fdđ1iďP±«ßB?¸ođ.ŃÄŃ}źAcP/ß#ßBFßBp×013q 2pÇ70 B2Aő1p `ô1dĽ˘F˙c˙´2µ˙´0µó˙1÷1˙1˙1ó´ż• ˙1˙1˙12$˙1gĐ˙3Y˙1˙1źą™*ŐH˙1ő1jüđ1LS°&Ń#T×đÜŃ5` ˛/sP •1Ż•č}
čc&pđ6Úup6eP1kR1?č˝;č P±ČSžńít0×S/au °z p3‘<[Ń2ąď P‘ëdr1rô '0 đ6±QF7˙–ÓçźvźvńCpUđyq–o ±˙ë3 řë¶ e r \ l# o c a ps t t i n# g s y cD p ”o v TdŐÄ. ´p T ÄR e 1 7 P6 4 c.p ** ( ah0l˝F “× Ř&ˇŁ& B  Ť
'  :
  F ÉČ! łm
#q’BH¨| Yp × <3 Ä …L €˛dF©:#żc{Gé _MU€|c‚s€”f€Ź-D W€ n d€wQ€“- SŠśS„ś; čÖŁH€5Wekodt·$/ D€0b u€Ë ë8p1÷˘ z ¶ ¦L€?S P ‡ C€TŞe€ćt€C€Ol€ĆVe€Řęo€ç €ÜaU€k€gŔsŔ3aAŔ e - mN:.¬ wJ:Á~a#t#"*r#pBk#r "_#w 5Ŕ1 ¨h 2ŔxŔAe#ŞyŔ0B'SŔa#jF#&rŔ*h#!ÁšeA#Q= 0 xŔ 0UĘ F#lŔ #nµŔcBeŔÁ!\Ŕ
Öh#A9\ÂhaB1ÁýÁe#!ÍłEoľ˙ĘÁĘľ6ŔFCĘŔ\ÁÇÁÉř ­bÄÉĹ˙ÉŘÉ• !ń#Ű rČÉ%őd%˙˙db0˙d#Ś˙d? + ëd€őĽ“™ #Š¨ z eŔp NÜc ż_á|ż_iŕYż_Î- Z ‹G <3á=á> cä>3ŢG˙Ł˙Ł ;ńŁżŕŁŔ­ś ±č>%ń>x'˙>˙>(q˙>˙>ů>飬·ŕŁáža o ?‡g`âµaŘo`Śdŕ‹Łŕ\ =­!ĺu ľ%ăe ™gŕ“Çá’ýĄć( 1ŕäˇĺ¶)ŕóĆH`śá˛. ›Zx` !ŕGŁ˘7#ÝF`í1 3 8 B E Aŕ: Ü ( ˇřˇĄr˘­%©QŻ4 8 Ę)PR#đÓ\n Hđ( ¬9 qQSd01đV7Đ18r4P FŐ°[DĐ 4 CP51XUgne\t0[Ő0A’epYp µ®AĐ
1q…tpb]f
2py
hq1ń1 dô1=˙1k˙˙ 12 ˙ú ő±đ1Q€ů˙1źó• ˙1˙2o ˙vsĐq nđ˙ńFrűź0opvźŐ˙ő®žđ1U1vpđ rĐW±ó‚‚r°ep wq4„tR„źTs6 „źTn2„0 Ö,"O°eP+Śęipnđ1lpŃ«11ş4ŇIP<ń“±&cđ
ZTu01’d’2fŐ0leđi“˙†ż˙†‘˙†‘ń‡UBhňęt0l°Bbp •“WQŐA9µ2801t¬ .q0ń0đ0eô0|Žž˙0˙0˙0˙0˙b4 »˙0#˙0 ßńb• ˙0˙0Ro˙0P˙˙´3X˙0˙0źą9 u#˙0Uő0¨đ0Cđ´Er!N[P
ńfJg p9o"QVc01S' b[0%38e ťÔ-pak0Ô‘3i’4uP'-[ňc1 rĐd±
-*x×p-Ńf1¶rđ.o~.Ń- S Y NXO°żE R`T I ˘O0F LĐ Gp¶=pb3m2e˛
¬ ń¶7]f
d˙/ëQu2p˛+˙¶“ýpcđźt_s›vů1Ş Đł5o5’1lń0q1xp1ft1'›Kż”ć˛ććA˘bvbüć1sb• 1˙1đߏß]FŐ,111e¶ t i n g S y pc / D e b u ë8p1÷  L śS P : T h± ¤ sre s i o –
f r Rp a ¨c k
g bs ć‚a e - m +¨c r 's f . w n d Şw M. 9l u  e x p Ar !*e­e o %t ˘_ 'w 5 1 Ş2 Ix —e My gÖ0 …1d =d c˘t ' 0€)0€E‰ € N‚# ±€+a l€ “ €Şa€2d€e€\'€>¨ E‚S€.s€UF€Rl€ €#nU€c€r€u€p\ \€ź,\‚€aׂ†Ĺ
e€`t€ «…°… \€=o„Ks€(k‡â…p‚(v€xrë€6ˇc€<l€;‘-MµÁ]p#[ ŔA>e#M€1 7 6 4Ŕ‚ lx ** 8Ŕgh K˛K“ ×  Ř&ˇŁ& "  ‘ Ä ”   Ŕ#Á
 # šŔ FA#Ő! #ł, #E’B H¨| YpŔ×<3 Ä E& A #
˛d F©:żc{4Gé€/MŔIKˇ- vWŔGˇ-Ŕ˝IMEË; čÖŁH€5Wekodtw©×ÝÂËÝCŔve#rÚt#~CŔ”Ae#A‹;ĂÝ˙Űoŕ!G˙mn «óm!„SbTn€7o`ćC$gc€= 1off?ătf­kf=qf6 Š2$f8`‘e káeÓáfŔ` häfś˙f˙föfˇ ! o rčf%őf%˙f ;!°oí ˝tŕ¦˙fn B˙f?pńŐőĽ“™ éa+ †"`żĎżĎżaąĎ€ŽB ˇ$ ˘á? Ĺ Źiä?h.L˙¦€—a§˙¦!
:€ ă¦ćÁঀ ±č?%˙Ŕ x • ˙S0Hő_1q_†˙iP!y€źź‘$SőŠ®ŻpSńP±QńGe0MaĐ »źw™wc˛uцD\ ×5±„gbe°u?«ůUA(R4t)0‹ßŃH˛t .°]Zx0 !PR“‰7PTFĐ1 3đD8 Bm0‡Ađ qV(
3ŠeŹĐ8ŐŚ_4 8ž ) Rđt0šr°‹Hpń 0 ‘©qNd ń d82Š8’4P F Cv 3 C°h1h±hn«P‹Qšt€{[PARŚÚeŤp UsAđ
1Őń‰tPš]°
ő1q1ĺő1jô1±3˙1…ł…­˙1°……v…˝đ1˙}…˙1s…• ˙1˙1˙1˙Ö­…SM˙1˙1źVŠ˙Ľý÷ĽŞđ11Ş“µ‘ąő»µ“şre˙Ľa0Âýżt Ń˙Ľ‘,˙ĽŐ4o˙Ľ˙Ľ˙…óĽ,0#ŐOGP=‘/·F l0 g´ sp( đ2ŃIĐ «±ÍQ'c°/T0/u0ő‘drf0ó±Dúe0l0.QKż»ń-ą»öh”=±»iđŐQHł÷Đő˙ Đ907Á1tžő1 kô1P×˙1˙1˙1 p2 ˙1ő÷1µ˙1#˙1óc• ˙˙1˙1˙1˙1˛VWę˙1˙1Ż˙1˙1˙1÷1˘đ1CpżîE˛!Ńŕ1fđJ¦‘áÖo2 Ű·bp%o°ž‘ŮVrđ%Ys’f0ií+ađ°qĽd0q(ű±Xń-đ)±·‘21ăQôFo^.‘^S YęC O PaR AUpůIĐ NđbLĐ Gí=0Ó
m01é±Đňµ 0 x 8 P0 4 Pf c d F i lD e čo n c o r u a p \ s hU 4l Ś\ .o *mQ bn g 6c *oD u Šs y zcU&e 2gfe.Ő “p w Yi 7— 2 5 7 a we s # ** lh ´®M “× Ř&ˇŁ& ! € €F€
‚D €
:€  ‘ Á!a€ ±6 #…8’BH¨| Yp€×<€3 x …LH ‚' ˛ dF©:żcP{Gé _M€Śc‚¬s€Ľf t -T W‚–d€w€ż-´ S€Ŕt€g€µ;čÖŁ H5Wekod˘t·$/ D#b#rg€Në8p1÷â ? ® S˙…˙…Ĺ…( 1Ŕ®7 6¬ )Ŕ’ÓEHŔMs#KŠ.Ŕ4xŔ ! 0D Š7€rFŔ’1 3#€8 B E AŔj:#ż(#ža#ťÁÂrŻ€~AËĂ
O
4#ŃD# ¨ RŔtŔMrŔŞVH#qÁ'1BtŔpdj Ád#8ÂÇŢF´ CŔ\ ŔĂ CŔŐUÁŘCŔ.nŔ.e#ętU#![#9AŔtŔmµŔĹtFAŔ+ÁvŔęt#ß]Ŕ
‚™ŔćÁĹ‹ÁÇÁÉmÄÇŁ4N˙c·˙c`ińcąŕcˇ\łčc˙%őc%˙c˙cb$˙c?mVe0 ÷c¦ŕcC`2Em"FN 7a2fŕ1c U 4o¤Jc iâ; ¬ b"ˇ{e s˘H+!áŞs €fŕr jm u žgŕ!Z-Ż`=ŁCáM!- xŕBVlâa p r J!
ˇwá[S Y ˘N NO P ^Rŕ^ T I O`F ęL G = b#aM˙!aáNˇˇaÇÇÇëÉ'Ç!&a-e }Çr ‚oĺĆ€ näb<ăĺ˙b˙ĆáËńb#ś! íb%ńbÄ'Ż˙b˘H˙ĆcQSP)nđ(ťciPĐĐ&o hń(źV‘1ucUP%S0%P’1TR„ łk‘ p|đ 1/ µ°,aĐkĐ+U/ap3e01±#c. wż1•r ń.Q+q2dp0Şlvň0yđ4apZQ3„r _pwp…nQ0eh 2PxeU0yĐ1 pnŐĐŤe0 ˛tpł0«5eu 0 Đ4op714łd“ P‘d uÓe'p P8±‘s×vßßePlpa~a0
3‘šąK™59\˝Poq ýF3p˛[ńdqrQEcl{đ żc°18 k°Ńz4’irq7qi#Ĺđ7oô7Ű+Oi›Ű˛››°››pťs›śÝ˙7˙7 ń7˙• ˙7›ĐV˙71 _3˙7ý›o˙7° ˙7ő7jĘpiLĐ7SĐ^ń[C˝°e‘11†±†eĐ ëb7tÔ-&7Q'»7ńZt3771p1Ő75CS˛*n›0ćC43A= ‘Ě8ż3˙ż3ż3ńcż3óż3ź0“żż3ż3s:u9ż3 P®>2yˇ3Ô7q3ń3Č pô3",˙3ĎuĎ ś2 ˙3÷3©Ä !0 rxť˙˙3ó3• ˙3˙3˙3Đ#˙3Q˙3˙3˙3ÔÔű3#őĽ“™ bŢŽËĐϡEpP0c ßh_1Ntđ‡ßhßhi ßheĐ9ßhÝh"T# 2+ńq pTqt j‰ y </td>
<td>Vertical gap between items</td>
</tr>
<tr>
<td>caption</td>
<td>
'pushTop'
<br>'pushDown'
<br>'revealBottom'
<br>'revealTop'
<br>'revealLeft'
<br>'moveRight'
<br>'overlayBottom'
<br>'overlayBottomPush'
<br>'overlayBottomReveal'
<br>'overlayBottomAlong'
<br>'overlayRightAlong'
<br>'minimal'
<br>'fadeIn'
<br>'zoom'
<br>'opacity'
</td>
<td>'pushTop'</td>
<td>Caption - the overlay that is shown when you put the mouse over an item. <br>NOTE: If you don't want to have captions set this option to an empty string (e.g. caption: '')</td>
</tr>
<tr>
<td>displayType</td>
<td>
'default'
<br>'bottomToTop'
<br>'fadeIn'
<br>'fadeInToTop'
<br>'sequentially'
</td>
<td>'fadeIn'</td>
<td>
The plugin will display his content based on the following values.
<br>- default (the content will be displayed without any animation)
<br>- fadeIn (e.g. lazyLoading) (the plugin will fully preload the images before displaying the items with a fadeIn effect)
<br>- fadeInToTop - fadeInToTop (the plugin will fully preload the images before displaying the items with a fadeIn effect from bottom to top)
<br>- sequentially (the plugin will fully preload the images before displaying the items with a sequentially effect)
<br>- bottomToTop (the plugin will fully preload the images before displaying the items with an animation from bottom to top)
</td>
</tr>
<tr>
<td>displayTypeSpeed</td>
<td>only integers, values in ms (e.g. 200, 300, 500)</td>
<td>400</td>
<td>Defines the speed of displaying the items (when <i>displayType: 'default'</i> this option will have no effect)</td>
</tr>
<tr>
<td>
lightboxDelegate
</td>
<td>strings that represent the elements in the document (DOM selector)</td>
<td>'.cbp-lightbox'</td>
<td>Define any clickable elements you wish to use to trigger lightbox popup on click. </td>
</tr>
<tr>
<td>
lightboxGallery
</td>
<td>true or false</td>
<td>true</td>
<td>Enable / disable gallery mode for lightbox popup</td>
</tr>
<tr>
<td>
lightboxTitleSrc
</td>
<td>HTML atributte</td>
<td>'data-title'</td>
<td>Attribute of the delegate item that contains caption for lightbox</td>
</tr>
<tr>
<td>
<span style="color: #D66767">lightboxShowCounter</span>
</td>
<td>-</td>
<td>-</td>
<td>This options is deprecated. Please use lightboxCounter option instead</td>
</tr>
<tr>
<td>
lightboxCounter
</td>
<td>HTML markup code</td>
<td>
'<div class="cbp-popup-lightbox-counter">{{current}} of {{total}}</div>'
</td>
<td>
Markup of the lightbox counter. To hide the counter for lightbox put this option to an empty string (e.g. '')
</td>
</tr>
<tr>
<td>
singlePageDelegate
</td>
<td>strings that represent the elements in the document (DOM selector)</td>
<td>'.cbp-singlePage'</td>
<td>Define any clickable elements you wish to use to trigger singlePage popup on click. </td>
</tr>
<tr>
<td>
singlePageDeeplinking
</td>
<td>true or false</td>
<td>true</td>
<td>Enable / disable the deeplinking feature for singlePage popup</td>
</tr>
<tr>
<td>
singlePageStickyNavigation
</td>
<td>true or false</td>
<td>true</td>
<td>Enable / disable the sticky navigation for singlePage popup</td>
</tr>
<tr>
<td>
<span style="color: #D66767">singlePageShowCounter</span>
</td>
<td>-</td>
<td>-</td>
<td>This options is deprecated. Please use singlePageCounter option instead</td>
</tr>
<tr>
<td>
singlePageCounter
</td>
<td>HTML markup code</td>
<td>
'<div class="cbp-popup-singlePage-counter">{{current}} of {{total}}</div>'
</td>
<td>
Markup of the singlePage counter. To hide the counter for singlePage put this option to an empty string (e.g. '')
</td>
</tr>
<tr>
<td>
singlePageAnimation
</td>
<td>
'left'
<br>'fade'
<br>'right'
</td>
<td>
'left'
</td>
<td>
Defines which animation to use when singlePage appear
</td>
</tr>
<tr>
<td>
singlePageCallback
</td>
<td>
function(url, element) { <br>
// to update singlePage content use the following method: this.updateSinglePage(yourContent)<br>
}
</td>
<td>null</td>
<td>Use this callback to update singlePage content. The callback will trigger after the singlePage popup is open. (#param url = the href attribute of the item clicked, #param element = the item clicked)</td>
<li class="page-item"><a class="page-link" href="javascript: void(0);">7</a></li>
<li class="page-item"><a class="page-link" href="javascript: void(0);">8</a></li>
<li class="page-item"><a class="page-link" href="javascript: void(0);">9</a></li>
<li class="page-item"><a class="page-link" href="javascript: void(0);">...</a></li>
<li class="page-item"><a class="page-link" href="javascript: void(0);">394</a></li>
<li class="page-item">
<a class="page-link" href="javascript: void(0);" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div> <!-- container -->
</div> <!-- content -->
<!-- Footer Start -->
<footer class="footer">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<script>
document.write(new Date().getFullYear())
</script> © Konektia - Wszystkie prawa zastrzeżone.
</div>
<div class="col-md-6">
<div class="text-md-right footer-links d-none d-md-block">
Wsparcie techniczne
Wyloguj
</div>
</div>
</div>
</div>
</footer>
<!-- end Footer -->
</div>
<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->
</div>
<!-- End -->
<div class="rightbar-overlay"></div>
<!-- /Right-bar -->
<!-- bundle -->
<script src="{% static 'assets/js/vendor.min.js' %}"></script>
<script src="{% static 'assets/js/app.min.js' %}"></script>
</body>
</html>
Is there any way to restore the file in classic form or change these unusual characters to correct HTML code? I tried to change the UTF encoding but to no avail (I use Windows 10).
How can I restore a deleted file in the correct form or change the html file restored to the correct form?
So I ran popular software to restore files (like CCleaner or Disk Drill), but the file I care about the most always looks the same (as in the photo below, this is the appearance after its restoration).
According to me you didn't permanently delete the file right? cause whenever a file is deleted it goes to the recycle bin...you could've easily restored it from there, but now there is no reason crying on spilt milk.
I think this should work as I have never seen this error...ping me if this works or not!
right click on the file, go to properties and then click on previous version and then if there is a previous version then jump in the air and yell hooray!
This link might help you!
That's all I have, welcome.

Ruby to get the value from HTML table which has same elements

I have a HTML file code which is shown below:
<table id="plans" class="brand-table">
<thead>
<tr>
<th class="domain">Plans</th>
<th class="basic">Basic</th>
<th class="plus">Plus</th>
<th class="prime">Prime</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>
www.test.com
</td>
<td>
<input name="upgrade" type="radio">
//this span element is hidden
<span class="plan_status"></span>
</td>
<td>
<input name="upgrade" value="plus www.test.com" type="radio">
//this span element is hidden
<span class="plan_status"></span>
</td>
<td>
<input name="upgrade" value="prime www.test.com" checked="" type="radio">
<span class="plan_status">current</span>
</td>
</tr>
</tbody>
</table>
I want to check which plan is the current plan in the page through Ruby Watir. Below is the script:
require 'watir'
browser = Watir::Browser.new(:chrome)
browser.goto('file:///C:/Users/Ashwin/Desktop/new.html')
browser.table(:id, 'plans').tds.each do |table_row|
if table_row.input(:value, 'plus www.test.com').text =~ /current/i
p 'current plan status is plus'
elsif table_row.input(:value, 'prime www.test.com').text =~ /current/i
p 'current plan status is prime'
else
p 'current plan status is basic'
end
end
But I am getting the output as:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/elements/element.rb:513:in `assert_exists': unable to locate element, using {:value=>"plus www.test.com", :tag_name=>"input"} (Watir::Exception::UnknownObjectException)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/elements/element.rb:86:in `text'
from C:/Users/Name/Documents/NetBeansProjects/RubyApplication6/lib/new_main15.rb:8:in `block in <main>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/element_collection.rb:29:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/element_collection.rb:29:in `each'
from C:/Users/Name/Documents/NetBeansProjects/RubyApplication6/lib/new_main15.rb:7:in `<main>'
But I want the output to be as:
current plan status is prime
Can anyone please help?
Thanks in advance
Instead of checking which td element has the "current" text, I would suggest checking which radio has the checked attribute. This reduces the number of elements you have to worry about interacting with.
You can find the selected radio using:
table_row.radios.find(&:set?).value
You can then check the value of the radio to see if it starts with the word "plus" or "prime":
# Note that we scope to the tbody to ignore the header row.
# Also make sure you do `trs` not `tds` for the rows.
table_rows = browser.table(id: 'plans').tbody.trs
# Iterate through the rows and check the checked radio button
table_rows.each do |table_row|
case table_row.radios.find(&:set?).value
when /^plus/
p 'current plan status is plus'
when /^prime/
p 'current plan status is prime'
else
p 'current plan status is basic'
end
end
Note that for older versions of Ruby (ie v1.9), you will need to find the selected radio using:
table_row.radios.find { |r| r.set? }.value

how do i create random letters in selenium ide?

I'm not an expert in Selenium IDE, I want to declare an array in Selenium IDE HTML and call it in the next line.
<tr>
<td>storeEval</td>
<td>new Array('en','de','da','cs','fi','fr','it','ja','ko','nl','no','pl','pt','ru','sv','tr')</td>
<td>myArray</td>
</tr>
<tr>
<td>type</td>
<td>FieldName</td>
<td>${myArray}</td>
</tr>
Thanks
Code below will randomly select item from array and type it to element with id=FieldName:
<tr>
<td>storeEval</td>
<td>var chars = 'en de da cs fi fr it ja ko nl no pl pt ru sv tr'.split(' '); str = chars[Math.floor(Math.random() * chars.length)];</td>
<td>item</td>
</tr>
<tr>
<td>type</td>
<td>FieldName</td>
<td>${item}</td>
</tr>
To access item from your initial array (lets say second item), you can add one more command:
<tr>
<td>storeEval</td>
<td>new Array('en','de','da','cs','fi','fr','it','ja','ko','nl','no','pl','pt','ru','sv','tr')</td>
<td>myArray</td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars['item'] = storedVars['myArray'][2]</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>FieldName</td>
<td>${item}</td>
</tr>
You can pass random int in range [0 .. length_of_array] to storedVars['myArray'][randomInt] to retrieve values randomly.

Advice for replacing img tags with text in Ruby?

I'm trying to work out how to store an html table of drive stats in a database, but the developers have been a bit clever, and started using gifs to represent pass/fail/health stats
Here's a snippet of what I've got:
<tr class="status">
<td class="status"><img border="0" src="/tick_green.gif"></td>
<td class="status">8</td>
<td class="status">Ready</td>
<td class="status"><img border="0" src="/bar10.gif"></td>
<td class="status">SEAGATE ST3146807FC</td>
<td class="status">10000 RPM</td>
<td class="status">3HY61AG9</td>
<td class="status">XR12</td>
<td class="status">286749488</td>
<td class="status"> 28.0°C</td>
<td class="status" style="background-color: #00fa00"> 
</td>
**
And here's some of the ruby that I've written so far to strip the tags:
table = page.parser.xpath('//table/caption[contains(.,"Drive")]/..')
table.xpath('//table//tr').each do |row|
row.xpath('td').each do |cell|
puts cell.to_html.gsub(/<a[^>]+>/,'').gsub(/<td[^>]+>/,'').gsub(/<\/td[^>]*>/,'').gsub(/<\/a[^>]*>/,'')
#puts cell.text
end
end
I can now get semi-rational output
<img border="0" src="/tick_green.gif">
15
Ready
<img border="0" src="/bar10.gif">
SEAGATE ST3146807FC
10000 RPM
3HY61ASW
XR12
286749488
29.0°C
 
But I want to replace a couple of other cell elements with other bits
For example, the tick_green can also be '/cross_red.gif' or '/caution.gif' which I want to replace with regular text, likewise, the img bar10.gif, I want to replace with just text of '10'
Is it best to come up with a whole bunch of values for all of my special cases?
I'd do some 'gsub'iing.
E.g.:
example = <<-STRING
<img border="0" src="/tick_green.gif">
15
Ready
<img border="0" src="/bar10.gif">
SEAGATE ST3146807FC
10000 RPM
3HY61ASW
XR12
286749488
29.0°C
 
STRING
replace = Hash.new("#unknown")
replace['tick_green.gif'] = "[OK]"
replace['bar10.gif'] = "[10]"
regex = /<img [^>]* src="\/(.*)">/
result = example.gsub(regex) { replace[$1] }
Somehow the I'd like to replace the $1 with a named backreference, but don't know how yet.
http://ruby-doc.org/core-1.9.3/String.html#method-i-gsub
edit: result from above
[OK]
15
Ready
[10]
SEAGATE ST3146807FC
10000 RPM
3HY61ASW
XR12
286749488
29.0°C
 
A case statement will clean that up a little but:
row.css('td').each do |td|
img = td.at('img')
puts case
when img && img[:src][/bar(\d+)\.gif/] then $1
when img && img[:src][/tick_green/] then 'ok'
else td.text.strip
end
end

How do I parse a plain HTML table with Nokogiri?

I'd like to parse a HTML page with the Nokogiri. There is a table in part of the page which does not use any specific ID. Is it possible to extract something like:
Today,3,455,34
Today,1,1300,3664
Today,10,100000,3444,
Yesterday,3454,5656,3
Yesterday,3545,1000,10
Yesterday,3411,36223,15
From this HTML:
<div id="__DailyStat__">
<table>
<tr class="blh"><th colspan="3">Today</th><th class="r" colspan="3">Yesterday</th></tr>
<tr class="blh"><th>Qnty</th><th>Size</th><th>Length</th><th class="r">Length</th><th class="r">Size</th><th class="r">Qnty</th></tr>
<tr class="blr">
<td>3</td>
<td>455</td>
<td>34</td>
<td class="r">3454</td>
<td class="r">5656</td>
<td class="r">3</td>
</tr>
<tr class="bla">
<td>1</td>
<td>1300</td>
<td>3664</td>
<td class="r">3545</td>
<td class="r">1000</td>
<td class="r">10</td>
</tr>
<tr class="blr">
<td>10</td>
<td>100000</td>
<td>3444</td>
<td class="r">3411</td>
<td class="r">36223</td>
<td class="r">15</td>
</tr>
</table>
</div>
As a quick and dirty first pass I'd do:
html = <<EOT
<div id="__DailyStat__">
<table>
<tr class="blh"><th colspan="3">Today</th><th class="r" colspan="3">Yesterday</th></tr>
<tr class="blh"><th>Qnty</th><th>Size</th><th>Length</th><th class="r">Length</th><th class="r">Size</th><th class="r">Qnty</th></tr>
<tr class="blr">
<td>3</td>
<td>455</td>
<td>34</td>
<td class="r">3454</td>
<td class="r">5656</td>
<td class="r">3</td>
</tr>
<tr class="bla">
<td>1</td>
<td>1300</td>
<td>3664</td>
<td class="r">3545</td>
<td class="r">1000</td>
<td class="r">10</td>
</tr>
<tr class="blr">
<td>10</td>
<td>100000</td>
<td>3444</td>
<td class="r">3411</td>
<td class="r">36223</td>
<td class="r">15</td>
</tr>
</table>
</div>
EOT
# Today Yesterday
# Qnty Size Length Length Size Qnty
# 3 455 34 3454 5656 3
# 1 1300 3664 3545 1000 10
# 10 100000 3444 3411 36223 15
require 'nokogiri'
doc = Nokogiri::HTML(html)
Use CSS to find the start of the table, and define some places to hold the data we're capturing:
table = doc.at('div#__DailyStat__ table')
today_data = []
yesterday_data = []
Loop over the rows in the table, rejecting the headers:
table.search('tr').each do |tr|
next if (tr['class'] == 'blh')
Initialize arrays to capture the pertinent data from each row, selectively push the data into the appropriate array:
today_td_data = [ 'Today' ]
yesterday_td_data = [ 'Yesterday' ]
tr.search('td').each do |td|
if (td['class'] == 'r')
yesterday_td_data << td.text.to_i
else
today_td_data << td.text.to_i
end
end
today_data << today_td_data
yesterday_data << yesterday_td_data
end
And output the data:
puts today_data.map{ |a| a.join(',') }
puts yesterday_data.map{ |a| a.join(',') }
> Today,3,455,34
> Today,1,1300,3664
> Today,10,100000,3444
> Yesterday,3454,5656,3
> Yesterday,3545,1000,10
> Yesterday,3411,36223,15
Just to help you visualize what's going, at the exit from the "tr" loop, the today_data and yesterday_data arrays are arrays-of-arrays looking like:
[["Today", 3, 455, 34], ["Today", 1, 1300, 3664], ["Today", 10, 100000, 3444]]
Alternatively, instead of looping over the "td" tags and sensing the class for the tag, I could have grabbed the contents of the "tr" and then used scan to grab the numbers and sliced the resulting array into "today" and "yesterday" arrays:
tr_data = tr.text.scan(/\d+/).map{ |i| i.to_i }
today_td_data = [ 'Today', *tr_data[0, 3] ]
yesterday_td_data = [ 'Yesterday', *tr_data[3, 3] ]
In real-world development, like at work, I'd use that instead of what I first wrote because it's succinct.
And notice that I didn't use XPath. It's very doable in Nokogiri to use XPath and accomplish this, but for simplicity I prefer CSS accessors. XPath would have allowed accessing individual "td" tag contents, but it also would begin to look like line-noise, which is something we want to avoid when writing code, because it impacts maintenance. I could also have used CSS to drill down to the correct "td" tags like 'tr td.r', but I don't think it would improve the code, it would just be an alternate way of doing it.

Resources