How to get TD text by TH name? - xpath

I'm using scrapy to parse a doc, this code is like my code structure that I want to parse, I want to get TD text by TH name, How ?
<div id="m_PanelField">
<table width="100%" cellspacing="1" border="0">
<tbody>
<tr>
<th>Etat</th>
<td>XyXy</td>
</tr>
<tr>
<th>IP</th>
<td>XX.XX.XX.XX</td>
</tr>
<tr>
<th>Alias</th>
<td>lorem ipsum</td>
</tr>
</tbody>
</table>
</div>

//td[../th='Etat'] OR .//tr[th='Etat']/td
Thank's for #helderdarocha and #paul-trmbrth

Related

Mailchimp edit table cell background color

Is there any logical way to change the background colour for a table cell in a repeatable region in mailchimp? Here is my code, I don't see any options in mailchimp with the custom template build.
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="content1">
<tbody>
<tr>
<td align="center" bgcolor="#ff0000" valign="middle" mc:edit="playlist"><h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4></td>
</tr>
</tbody>
</table>
I came across a similar issue today. Here's a possible solution:
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="red">
<tbody>
<tr>
<td align="center" bgcolor="#ff0000" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="green">
<tbody>
<tr>
<td align="center" bgcolor="#00ff00" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="blue">
<tbody>
<tr>
<td align="center" bgcolor="#0000ff" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
When you've imported this into your template, create a campaign and on the design page you'll have a dropdown with the different colour options. Make any h2s, h3s etc editable by adding mc:edit.

How to get second td class if i know first

My first question here, sorry if i do something wrong.
I have code
<div class="detail_block_param">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="name">1st par</td>
<td class="value">Swiss</td>
</tr>
</table>
</div><div class="detail_block_param">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="name">2nd par</td>
<td class="value">mechanic</td>
</tr>
</table>
I need to get "value" class if name="1st par".
I try
//h:td[2][*[contains(.,'1st par')]]/../h:td[last()]/h:a/text()
but its not worked for me.
Thanks!
Try something like:
'//td[#class="name"][contains(text(), "1st par")]/following-sibling::td[#class="value"]'
If you wish to do it using JQuery...Here is the solution:
$(".detail_block_param td:contains('1st par')").next().html()
Fiddler result for the same:
http://jsfiddle.net/CPQ8C/

problems with xpath evaluation

If I want to extract hrefs only under Type1, basically, 1,2,3,4. htm but not including 5.htm, how to do that?
What I have for now is ://table[#class='leftnav']//a"
Thanks !
<table width="240" border="0" cellpadding="0" cellspacing="0" class="leftnav">
<tr class="leftnav">
<th>Type1</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
<tr class="leftnav">
<td>2012</td>
</tr>
<tr class="leftnav">
<td>2011</td>
</tr>
<tr class="leftnav">
<td>2010</td>
</tr>
<tr class="leftnav">
<th>Type2</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
</table>
Try this xpath:
//tr[(preceding-sibling::tr/th)[last()]="Type1"]/td/a

Combine th:each with templating element using Thymeleaf

I have a list of 'product' which I want to show as a list of row table using an html template.
The html template looks like:
<tr th:fragment="productTemplate">
<td th:text="${productName}">product name</td>
<td th:text="${productprice}>product price</td>
</tr>
Here is what I did:
<table>
<tr th:each="product : ${products}" th:substituteby="product :: productTemplate" th:with="productName=*{name}, productPrice=*{price}" />
</table>
If I use th:include, there will be tr nested to each tr
If I use th:substituteby, substitute has the priority on th:each
I cant find a way to replace my loop items by an other.
Somebody have a solution to do this?
I got it:
<table>
<tr th:each="product : ${products}" th:include="product :: productTemplate"
th:with="productName=${product.name}, productPrice=${product.price}"
th:remove="tag" />
</table>
And here, we can keep the template class on the tr element (that what I wanted)
<tbody th:fragment="productTemplate">
<tr class="my-class">
<td th:text="${productName}">product name</td>
<td th:text="${productPrice}">product price</td>
</tr>
</tbody>
here's the result:
<table>
<tr class="my-class">
<td>Lettuce</td>
<td>12.0</td>
</tr>
<tr class="my-class">
<td>Apricot</td>
<td>8.0</td>
</tr>
</table>
thanks to danielfernandez from the official thymeleaf forum
th:include is what you are looking for. The code below works for me. I prefer to put multiple fragments in one file so I've included that here.
<table>
<tr th:each="product : ${products}" th:include="/fragments/productFragment :: productRow" />
</table>
...
/fragments/productFragment.html
...
<tr th:fragment="productRow">
<td th:text="${product.productName}">product name</td>
<td th:text="${product.productPrice}">product price</td>
</tr>
...

How to get id element in datatable

I using datatable plugin (datatables.net) with code below
How can i click anywhere in datatable to get image id
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th></th>
<th>Rendering engine</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Engine version</th>
<th>CSS grade</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td><img id='1' href='#' src='Images/details_open.png'/></td>
<td>Trident</td>
<td>Internet Explorer 4.0</td>
<td>Win 95+</td>
<td class="center">4</td>
<td class="center">X</td>
</tr>
<tr class="gradeC">
<td><td><img id='2' href='#' src='Images/details_open.png'/></td></td>
<td>Trident</td>
<td>Internet Explorer 5.0</td>
<td>Win 95+</td>
<td class="center">5</td>
<td class="center">C</td>
</tr>
</tbody>
</table>
Thanks very much
I use another way to resolve this problem :
I set hiden colum and use function :fnGetData to get id from this hiden row.

Resources