Get tr having specific th value from the table having an id using Xpath - python-3.x

I am using python3.6 with XPath library. Crawling inside the table gives me an empty list. And need to crawl to specific th.
My tr contents are dynamically generated. I need to crawl to tr which has a specific th value. Example In HTML code, the Rank appears in the second tr but it can appear in anywhere in tr. It doesn't have a specific index. Need to get the href from the tr having the Rank th.
My html file:
<tbody>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Product Number
</th>
<td class="a-size-base">
B003NR57BY
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Rank
</th>
<td>
<span>
<span>#3 in Computer Mice</span>
<br>
</span>
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">
Created Date
</th>
<td class="a-size-base">
June 7, 2010
</td>
</tr>
</tbody>
</table>
Python code:
listings_details = parser.xpath(XPATH_PRODUCT_DETAILS)
for row in listings_details:
th = row.xpath("./th/text()")
if th[0].strip() == 'Rank':
categories = row.xpath("./td/span/span//text()")
qid_url= row.xpath("./td/span/span//#href")
I expect the output to be
Rank: 3,
url : /gp/bestsellers/pc/11036491/ref=pd_zg_hrsr_pc_1_1_last,
category: Computer Mice

Need to get the href from the tr having the Rank th.
Use:
/table/tbody/tr[normalize-space(th)='Rank']/td//a/#href
Note: this works for your provided fragment (now well-formed). You need to add later a context for selecting the table element.
<table>
<tbody>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Product Number</th>
<td class="a-size-base">B003NR57BY</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Rank</th>
<td>
<span>
<span>#3 in
Computer Mice
</span>
<br/>
</span>
</td>
</tr>
<tr>
<th class="a-color-secondary a-size-base prodDetSectionEntry">Created Date</th>
<td class="a-size-base">June 7, 2010</td>
</tr>
</tbody>
</table>
Test in http://www.xpathtester.com/xpath/53808ee94dfbc5b38f12791cf857ffb9

Related

How to remove row gap between two tables in Laravel maatwebsite/excel FromView

I want to export order and order item data in my laravel web app in xls format so i decided to try using maatwebsite/excel v3.1. I'm using FromView class to convert blade template into an excel file, the blade structure looks like this:
<table>
<thead>
<tr>
<th> Order# </th>
<th> Customer </th>
<th> Order Date </th>
<th> Total </th>
</tr>
</thead>
<tbody>
<tr>
<td> 1132 </td>
<td> Ashin </td>
<td> 21-11-2021 </td>
<td> 3000.00$ </td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th colspan="4"> Order Items </th>
</tr>
<tr>
<th> Product </th>
<th> Price </th>
<th> Qty </th>
<th> Subtotal </th>
</tr>
</thead>
<tbody>
<tr>
<td> Bag </td>
<td> 1200.00$ </td>
<td> 2 </td>
<td> 2400.00$ </td>
</tr>
<tr>
<td> Hat </td>
<td> 600.00$ </td>
<td> 1 </td>
<td> 600.00$ </td>
</tr>
</tbody>
</table>
and the results looks like this:
there is a row gap between these two tables, how can i remove it?

Creating a custom button in Jodit Editor

I'm trying to create a custom table button using Jodit React Editor using this as reference - https://xdsoft.net/jodit/examples/toolbar/custom_button.html
I'm a little lost on this though.
I need to be able to create a table and have the icon be a text icon that says - "Table"
Right now I've added this to my configurations - extraButtons: ['tableNew'].
I've also added the below code to the render method.
this.jodit.options.controls.tableNew = {
iconURL: '',
exec: function (editor) {
return '<table> <thead> <tr> <th> Sl no </th> <th>Name</th> <th>Age</th> </tr> </thead>'+
' <tbody> <tr> <td>1</td> <td></td> <td></td> </tr> </tbody> </table>';
}
};
I see that a space has been added in the toolbar which on hover says tableNew but on clicking it nothing happens.
I'd really appreciate it if someone could help me out with this.
Instead of the following,
return '<table> <thead> <tr> <th> Sl no </th> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> <tr> <td>1</td> <td></td> <td></td> </tr> </tbody> </table>';
try something like this:
return editor.create.fromHTML('<table> <thead> <tr> <th> Sl no </th> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> <tr> <td>1</td> <td></td> <td></td> </tr> </tbody> </table>');
This works for me (a similiar implementation, not returning table like you, but return some list).

Excel VBA getElementsByTagName

i'm trying to get a complex (ugly) nested table with no id but with a class name = "tableselect" then read all tr's and td's
the only quick and unique way to find the table - it is within a div tag, then a center tag.
this is the html structure.
<div align="center">
<center>
<table border='1' width='100%' cellspacing='0' cellpadding='5' class="tableselect">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
...
</table>
</center>
</div>
the .getElementsByTagName("center").getElementsByTagName("table") does not work
also
.getElementsByClassName("tableselect").getElementsByTagName("tr") does not work
using excel 2016

How to pass product TVs to SimpleCart's scGetCart snippet?

I need some TVs (weight, dimensions, etc) I've associated with my products to appear in the Cart page of my SimpleCart site.
Problem is I have no idea how to do this. I don't understand how the SimpleCart cart is built and there isn't documentation for this.
Would anyone know how I can show TVs associated with each product in the cart output chunk?
The cart snippet has the following code which gets data from the cart and puts it into Chunks:
$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return '';
 
$controller = $sc->loadController('Cart');
$output = $controller->run($scriptProperties);
The output Chunk looks like:
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<table>
<tr>
<th class="desc">[[%simplecart.cart.description]]</th>
<th class="price">[[%simplecart.cart.price]]</th>
<th class="quantity">[[%simplecart.cart.quantity]]</th>
[[+cart.total.vat_total:notempty=`<th class="quantity">[[%simplecart.cart.vat]]</th>`:isempty=``]]
<th class="subtotal">[[%simplecart.cart.subtotal]]</th>
<th> </th>
</tr>
[[+cart.wrapper]]
[[+cart.total.discount:notempty=`<tr class="total first discount">
<td colspan="[[+cart.total.vat_total:notempty=`3`:isempty=`2`]]"> </td>
<td class="label">[[%simplecart.cart.discount]]</td>
<td class="value">- [[+cart.total.discount_formatted]]</td>
<td class="extra">[[+cart.total.discount_percent:notempty=`([[+cart.total.discount_percent]]%)`:isempty=` `]]</td>
</tr>`:isempty=``]]
[[+cart.total.vat_total:notempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_ex_vat]]</td>
<td class="value">[[+cart.total.price_ex_vat_formatted]]</td>
<td class="extra"> </td>
</tr>
[[+cart.vat_rates]]
<tr class="total [[+cart.total.discount:notempty=`third`:isempty=`second`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_vat]]</td>
<td class="value">[[+cart.total.vat_total_formatted]]</td>
<td class="extra"> </td>
</tr>
<tr class="total [[+cart.total.discount:notempty=`fourth`:isempty=`third`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_in_vat]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`:isempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="2"> </td>
<td class="label">[[%simplecart.cart.total]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`]]
</table>
<div class="submit">
<input type="submit" value="[[%simplecart.cart.update]]" />
</div>
</form>
This does appear to be documented:
Product Options (TVs)
and to output them:
Modifying the Product Template
It appears that you would just output them normally [[*myProductOptions]]
Though, it appears that your template is using a placeholder, I would try
[[+cart.myProductOptions] as well. If all else fails you might try debugging the simplecart class and dump the array of product data before it populates the chunk, there might be a clue in there.
Found (through trial and error) you must use:
[[+product.tv.name_of_tv]]

How can I generate a table with sections with Jade?

Thanks in advance for taking the time to try to help. I am using the Jade templating engine in node.js, and want to generate an HTML table with rows grouped into sections (tbody tags).
Let's say I have the following object in memory:
[
{ type: 'Fruit', name: 'Apple' }
, { type: 'Fruit', name: 'Orange' }
, { type: 'Vegetable', name: 'Carrot' }
, { type: 'Vegetable', name: 'Spinach'}
]
(for simplicity, let's assume the array comes pre-ordered by the "type" column).
And I want to generate a table with rows for each object inside a tbody section for each "type" (Fruit vs. Vegetable). So the HTML I'm trying to generate is:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit">
<tr>
<td>Fruit</td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit</td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable">
<tr>
<td>Vegetable</td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable</td>
<td>Spinach</td>
</tr>
</tbody>
</table>
I think I would want my jade to look something like:
table
thead
th Type
th Name
- var lastType;
each o in objs
- if(o.type != lastType)
tbody(id='#{o.type}')
- lastType = o.type;
tr
td #{o.type}
td #{o.name}
But this generates:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit" />
<tbody>
<tr>
<td>Fruit</td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit</td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable" />
<tbody>
<tr>
<td>Vegetable</td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable</td>
<td>Spinach</td>
</tr>
</tbody>
</table>
Any ideas?
This is in Jade kinda hard to guess, because we don't really see how your indentations are really set in your local code, but here(your posted snippet) it seems like your indentations are not right.
You should try this: +Update (added another loop to get all same types under each body)
table
thead
th Type
th Name
- var lastType;
each o in objs
- if (o.type != lastType)
- lastType = o.type;
tbody(id='#{o.type}')
each t in objs
- if(t.type === lastType)
tr
td #{t.type}
td #{t.name}
Just shift the both tr tags into your tbody, like my code example above.
+Update This will produce this HTML code now:
<table>
<thead>
<th>Type</th>
<th>Name</th>
</thead>
<tbody id="Fruit">
<tr>
<td>Fruit </td>
<td>Apple</td>
</tr>
<tr>
<td>Fruit </td>
<td>Orange</td>
</tr>
</tbody>
<tbody id="Vegetable">
<tr>
<td>Vegetable </td>
<td>Carrot</td>
</tr>
<tr>
<td>Vegetable </td>
<td>Spinach</td>
</tr>
</tbody>
</table>
table
thead
th Type
th Name
tbody#Fruit
tbody
tr
td Fruit
td Apple
tr
td Fruit
td Orange
tbody#Vegetable
tbody
tr
td Vegetable
td Carrot
tr
td Vegetable
td Spinach
You should go with pug basic formate to list the following process

Resources