Get link inside several p elements using xpath - xpath

I have the following code (as part of a page):
<div class="examples">
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
</div>
I'm trying to get the link (href and title) using xpath. There are several "update" p class elements on the same page, i need them all. I'm not really interested for the "Day 1 : " text (or whatever day gets there).
Is this possible?
Thanks.

One possible xpath :
//div[#class='examples']/p[#class='update']/a
Output :
'exampletext'
'exampletext'
'exampletext'
'exampletext'
'exampletext'
'exampletext'

Related

Sphinx anchor defined twice (singlehtml output)

I have a sphinx project which uses figures and footnotes. I noticed that as soon as I include a caption in figures, the ids rendered in HTML are defined twice.
For example, consider a minimal project like this:
Project Example
===============
this is index.rst
.. toctree::
:maxdepth: 2
:caption: Contents:
inc
hello [#0]_ world:
We should expect that footnote 0 [#1]_ would have `id1`, and footnote 2 `id2`
.. [#0] Lorem Impsum.
.. [#1] Lorem Impsum.
And inc.rst:
Included
========
.. figure:: _static/cat.jpg
:scale: 20%
:align: center
This is a caption
Running sphinx-build -M singlehtml "." "_build" renders:
<span id="document-inc"></span><section id="included">
<h2>Included<a class="headerlink" href="#included" title="Permalink to this headline">¶</a></h2>
<figure class="align-center" id="id1">
<a ...></a>
<figcaption>
<p><span class="caption-text">This is a caption</span><a class="headerlink" href="#id1" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
</section>
</div>
<p>We should expect that operator <a class="footnote-reference brackets" href="#id3" id="id1">2</a> would:</p>
<p>We should expect that operator <a class="footnote-reference brackets" href="#id4" id="id2">3</a> would:</p>
<dl class="footnote brackets">
<dt class="label" id="id3"><span class="brackets"><a class="fn-backref" href="#id1">2</a></span></dt>
<dd><p>Lorem Impsum.</p>
</dd>
<dt class="label" id="id4"><span class="brackets"><a class="fn-backref" href="#id2">3</a></span></dt>
<dd><p>Lorem Impsum.</p>
</dd>
</dl>
If I remove the caption, the figure opening HTML is rendered without id="id1", like this:
<figure class="align-center">
Is this a bug in sphinx?
Can I tell sphinx use the following id in figure to avoid collisions?

Laravel Display Many to Many with Pivot in Blade

Background:
I have a pivot table with Medication, Patient with pivot element day, time, given, given by and lock.
Example:
id medication_id patient_id Day time given
1 1 (MED X) 1 (Patient X) Yesterday 0900 1
2 1 (MED X) 1 (Patient X) Yesterday 1200 1
3 1 (MED X) 1 (Patient X) Today 0900 0
4 2 (MED Y) 1 (Patient X) Tomorrow 1200 0
5 2 (MED Y) 1 (Patient X) Yesterday 0900 1
6 1 (MED X) 2 (Patient Y) Yesterday 1200 1
7 1 (MED X) 2 (Patient Y) Yesterday 0900 1
8 3 (MED Z) 2 (Patient Y) Yesterday 1200 0
A patient can have the same medication but at multiple times within the same day. Let's say Patient X had Med X yesterday at 0900 and 1200, today at 0900 but not tomorrow.
To see all the Medication assigned to the Patient X
$assignedMeds = $patient->medication()->get();
And passed it into the view.
What I have right now is
#if(isset($assignedMeds))
<div class="card-body">
<table class="table table-hover">
<tbody>
<tr>
<th>Name</th>
<th>Yesterday</th>
<th>Today</th>
<th>Tomorrow</th>
</tr>
#foreach($assignedMeds as $assignedMed)
<tr>
<td>{{$assignedMed->name}}</td>
<td>
#if(($assignedMed->pivot->day) == 'yesterday')
#if($assignedMed->pivot->given)
<i class="fas fa-check green"></i>
<strike>{{$assignedMed->pivot->time}}</strike>
<em>{{$assignedMed->pivot->givenby}}</em>
#else
{{$assignedMed->pivot->time}}
#endif
#endif
</td>
<td>
#if(($assignedMed->pivot->day) == 'today')
#if($assignedMed->pivot->given)
<i class="fas fa-check green"></i>
<strike>{{$assignedMed->pivot->time}}</strike>
<em>{{$assignedMed->pivot->givenby}}</em>
#else
<form method="post" action="/mar/{{$assignedMed->id}}">
#csrf
#method('PATCH')
<input hidden name="givenby" id="givenby" value="1">
<button>{{$assignedMed->pivot->time}}</button>
</form>
#endif
#endif
</td>
<td>
#if(($assignedMed->pivot->day) == 'tomorrow')
{{$assignedMed->pivot->time}}
#endif
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endif
And it gives me
Medication Name Yesterday Today Tomorrow
Med X 0900 Given
Med X 0900
Med X 1200 Given
Med Y 0900 Given
Med Y 0900
What I am looking for
What I am trying to get is to display the name of medication once and show the time in it.
Example for Patient X
Medication Name Yesterday Today Tomorrow
Med X 0900 Given 0900
1200 Given
Med Y 0900 Given 0900
You could use the groupBy() and where() Collection methods in your #foreach. It should end up looking like this.
<!-- $index will be the 'name' we grouped by (medication name) -->
#foreach($assignedMeds->groupBy('name') as $index => $assignedMed)
<tr>
<!-- medication name -->
<td>{{ $index }}</td>
<!-- yesterday's medications -->
<td>
#foreach($assignedMed->where('pivot.day', 'Yesterday') as $yesterdaysMeds)
#if($yesterdaysMeds->pivot->given)
<i class="fas fa-check green"></i>
<strike>{{$yesterdaysMeds->pivot->time}}</strike>
<em>{{$yesterdaysMeds->pivot->givenby}}</em>
#else
{{$yesterdaysMeds->pivot->time}}
#endif
<!-- line break -->
<br>
#endforeach
</td>
<!-- today's medications -->
<td>
#foreach($assignedMed->where('pivot.day', 'Today') as $todaysMeds)
#if($todaysMeds->pivot->given)
<i class="fas fa-check green"></i>
<strike>{{$todaysMeds->pivot->time}}</strike>
<em>{{$todaysMeds->pivot->givenby}}</em>
#else
<form method="post" action="/mar/{{$todaysMeds->id}}">
#csrf
#method('PATCH')
<input hidden name="givenby" id="givenby" value="1">
<button>{{$todaysMeds->pivot->time}}</button>
</form>
#endif
<!-- line break -->
<br>
#endforeach
</td>
<!-- tomorrow's medications -->
<td>
#foreach($assignedMed->where('pivot.day', 'Tomorrow') as $tomorrowsMeds)
{{ $tomorrowsMeds->pivot->time }}
<!-- line break -->
<br>
#endforeach
</td>
</tr>
#endforeach

How can I search a table faster?

I am trying to search a table for specific a specific value using Ruby and Selenium-webdriver. I have a method that works but takes a lot of time for some reason. It is a one row table and the page HTML looks like this:
<div id="permitGridContainer">
<table id="calendar" class="items" style="width:430px;" name="calendar">
<thead>
<tbody>
<tr>
<td id="avail1" class="status r slct" onmouseout="return nd();" onmouseover="return overlib("Available Quota<br>River Launches : 0 of 4");">
<div class="permitStatus">R</div>
</td>
<td id="avail2" class="status r" onmouseout="return nd();" onmouseover="return overlib("Available Quota<br>River Launches : 0 of 4");">
<div class="permitStatus">R</div>
</td>
<td id="avail3" class="status a" onmouseout="return nd();" onmouseover="return overlib("Available Quota<br>River Launches : 89 of 99");">
<a onclick="javascript:setNewArrivalDate("Sun Sep 06 2015", 2);return false;" href="#">
A
<br>
<small>89</small>
</a>
</td>
<td id="avail4" class="status a" onmouseout="return nd();" onmouseover="return overlib("Available Quota<br>River Launches : 97 of 99");">
</tr>
</tbody>
</table>
</div>
... I shortened the table it has 14 columns.
I am looking for a column that has an Item available and I am checking the class for this, but the text also changes so there are other things I could look for.
This is the code I am using, but it visibly slow. I used puts statements to see the progress. My sense is that is has to do with time accessing the element. So I was hoping there is a better way to process the table quickly. Thank you.
for j in 1..days_to_check[i]
check_avail = driver.find_element(id: "avail#{j}")
check_availclass = check_avail.attribute ("class")
if check_availclass == "status a" or check_availclass == "status a slct"
#process if
end
Depending on your comment I would suggest to use the following xpath. I find this is often easier and feasible to use better xpath than looping though the html table
//td[(#class='status a') or (#class='status A')]
This xpath finds the class with status a or status A

Using if condition to display data in Blade

How print value in this code:
<li class="price-val">{{ $value->price ? '$value->price € month<span class="price-fea-ct">*VAT Included</span>':'$value->price € month' }}</li>
$value->price variable is have 0 & 9 value respectively.but it does print value.print $value->price just.
Something like this should work
<li class="price-val">
#if ($value->price)
{{{ $value->price }}} € month<span class="price-fea-ct">*VAT Included</span>
#else
{{{ $value->price }}} € month
#endif
</li>
However for me the condition doesn't make sense - if price is 0 you will display 0 / month and it does not seem to be logical
You have syntax errors, try this:
<li class="price-val">
{{
$value->price ?
$value->price . '€ month <span class="price-fea-ct">*VAT Included</span>' :
$value->price . '€ month'
}}
</li>

Filter/Exclude xPath extraction via "pattern"

This is what I have to work with:
<div class="Pictures zoom">
<a title="Productname 1" class="zoomThumbActive" rel="{gallery: 'gallery1', smallimage: '/images/2.24198/little_one.jpeg', largeimage: '/images/76.24561/big-one-picture.jpeg'}" href="javascript:void(0)" style="border-width:inherit;">
<img title="Productname 1" src="/images/24.245/mini-doge-picture.jpeg" alt="" /></a>
<a title="Productname 1" rel="{gallery: 'gallery1', smallimage: '/images/2.24203/small_one.jpeg', largeimage: '/images/9.5664/very-big-one-picture.jpeg'}" href="javascript:void(0)" style="border-width:inherit;">
<img title="Productname 1" src="/images/22.999/this-picture-is-very-small.jpeg" alt="" /></a>
<div>
Using following Xpath:
/html//div[#class='Pictures zoom']/a/#rel
The output becomes:
{gallery: 'gallery1', smallimage: '/images/2.24198/little_one.jpeg', largeimage: '/images/76.24561/big-one-picture.jpeg'}
{gallery: 'gallery1', smallimage: '/images/2.24203/small_one.jpeg', largeimage: '/images/9.5664/very-big-one-picture.jpeg'}
Is it possible to filter the extraction, so intread of above, I only get these:
/images/76.24561/big-one-picture.jpeg
/images/9.5664/very-big-one-picture.jpeg
I only wish to keep everything between largeimage: ' and '}
Best regards,
Liu Kang
Use substring-before and substring-after to cut of the parts you do not want.
Using XPath 1.0, this can only be done for single results (so you cannot fetch all URLs contained in one document with a single XPath call). This query will return the first URL:
substring-before(substring-after((//#rel)[1], "largeimage: '"), "'")
XPath 2.0 allows you to run functions as axis steps. This query will return all URLs you're looking for as single tokens:
//#rel/substring-before(substring-after(., "largeimage: '"), "'")

Resources