C# Html Agility Pack : Remove 2 columns on a table - c#-4.0

I am trying to remove 2 columns on a table which inside a div which has a attribute "data-group" with value "Revision". The problem is it is removing 2 columns on all the tables or not doing anything.
Below is the code:
string htmlDoc = #"
<div id='TestCo_1' class='view' data-routingURI='ViewRouter.aspx' data-view='TestCo_1' data-filters='' data-viewVersion='2' data-vmVersion='2.2.0.0'>
<div id='g1' class='group' data-group='Reddy,HEATHER+M'>
<div id='gh1' class='gh' style='margin-left:10px;'>
<img id='gti1' class='gti' src='Images/closed.png'/>
<span id='gt1' class='gt'>Reddy,HEATHER M</span>
<a id='ge1' class='groupExport'>
<img src='Images/excel.png' title='Excel export Reddy,HEATHER M' class='export'/>
</a>
</div>
<div id='gc1' class='gc'/>
<div id='g2' class='group' data-group='Reddy,HEATHER+M/Data+Check+Status'>
<div id='gh2' class='gh' style='margin-left:60px;'>
<img id='gti2' class='gti' src='Images/closed.png'/>
<span id='gt2' class='gt'>Data Check Status</span>
<a id='ge2' class='groupExport'>
<img src='Images/excel.png' title='Excel export Data Check Status' class='export'/>
</a>
</div>
<div id='gc2' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311085;id:763;status:Data+Check+Status;'>311085</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>KEDRION BIOPHARMA INC</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Data Checks Review Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
<div id='g3' class='group' data-group='Reddy,HEATHER+M/ER+Funding+Status'>
<div id='gh3' class='gh' style='margin-left:60px;'>
<img id='gti3' class='gti' src='Images/closed.png'/>
<span id='gt3' class='gt'>ER Funding Status</span>
<a id='ge3' class='groupExport'>
<img src='Images/excel.png' title='Excel export ER Funding Status' class='export'/>
</a>
</div>
<div id='gc3' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311077;id:377;status:ER+Funding+Status;'>311077</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>APPLE ROCK ADVERTISING AND PRO</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS ER Funding Follow Up Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:51212105;id:1506;status:ER+Funding+Status;'>51212105</td>
<td>2012</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>WORD ACADEMIES, INC.</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS ER Funding Follow Up Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:51212105;id:390;status:ER+Funding+Status;'>51212105</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>WORD ACADEMIES, INC.</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS ER Funding Follow Up Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
<div id='g4' class='group' data-group='Reddy,HEATHER+M/Match+Verification+Status'>
<div id='gh4' class='gh' style='margin-left:60px;'>
<img id='gti4' class='gti' src='Images/closed.png'/>
<span id='gt4' class='gt'>Match Verification Status</span>
<a id='ge4' class='groupExport'>
<img src='Images/excel.png' title='Excel export Match Verification Status' class='export'/>
</a>
</div>
<div id='gc4' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311085;id:763;status:Match+Verification+Status;'>311085</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>KEDRION BIOPHARMA INC</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Match Verification Review Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
<div id='g5' class='group' data-group='Reddy,HEATHER+M/Plan+Contact+Status'>
<div id='gh5' class='gh' style='margin-left:60px;'>
<img id='gti5' class='gti' src='Images/closed.png'/>
<span id='gt5' class='gt'>Plan Contact Status</span>
<a id='ge5' class='groupExport'>
<img src='Images/excel.png' title='Excel export Plan Contact Status' class='export'/>
</a>
</div>
<div id='gc5' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311026;id:0;status:Plan+Contact+Status;'>311026</td>
<td/>
<td style='text-align:center;'/>
<td style='text-align:center;'/>
<td>INSTITUTE OF FINANCIAL OPERATI</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Contacts Undeliverable</td>
<td style='text-align:center;'>Florida</td>
</tr>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311036;id:0;status:Plan+Contact+Status;'>311036</td>
<td/>
<td style='text-align:center;'/>
<td style='text-align:center;'/>
<td>VOTENET SOLUTIONS, INC</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Contacts Undeliverable</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
<div id='g6' class='group' data-group='Reddy,HEATHER+M/Revision+Status'>
<div id='gh6' class='gh' style='margin-left:60px;'>
<img id='gti6' class='gti' src='Images/closed.png'/>
<span id='gt6' class='gt'>Revision Status</span>
<a id='ge6' class='groupExport'>
<img src='Images/excel.png' title='Excel export Revision Status' class='export'/>
</a>
</div>
<div id='gc6' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:51212105;id:779;status:Revision+Status;'>51212105</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>WORD ACADEMIES, INC.</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Additional Data Requested</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
<div id='g7' class='group' data-group='Reddy,HEATHER+M/Testing+Status'>
<div id='gh7' class='gh' style='margin-left:60px;'>
<img id='gti7' class='gti' src='Images/closed.png'/>
<span id='gt7' class='gt'>Testing Status</span>
<a id='ge7' class='groupExport'>
<img src='Images/excel.png' title='Excel export Testing Status' class='export'/>
</a>
</div>
<div id='gc7' class='gc'>
<table border='0' class='groupTable' style='margin-left:110px;color:black; background-color:White;'>
<thead>
<tr style='margin-left:60px;color:blue; background-color:White; '>
<th style='text-align:center;' width='50px'>RK ID</th>
<th width='80px'>Plan Year</th>
<th style='text-align:center;' width='80px'>Period</th>
<th style='text-align:center;' width='80px'>Plan Term Date</th>
<th width='300px'>Subscriber Name</th>
<th width='300px'>Plan Market</th>
<th width='300px'>TestCoTS Review Requested</th>
<th width='400px'>Status</th>
<th width='60px'>Region</th>
</tr>
</thead>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:51212105;id:779;status:Testing+Status;'>51212105</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>WORD ACADEMIES, INC.</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Testing Review Requested - Failed</td>
<td style='text-align:center;'>Florida</td>
</tr>
<tr class='dtl'>
<td style='text-align:center;' class='link' data-target='ae:311083;id:759;status:Testing+Status;'>311083</td>
<td>2013</td>
<td style='text-align:center;'>Year End</td>
<td style='text-align:center;'/>
<td>REDI-GROUP NORTH AMERICA, LLC</td>
<td/>
<td/>
<td style='font-weight:bold;'>TestCoTS Testing Review Requested - Failed</td>
<td style='text-align:center;'>Florida</td>
</tr>
</table>
</div>
</div>
</div>
</div>";
HtmlDocument myhtmlDoc = new HtmlDocument();
myhtmlDoc.LoadHtml(htmlDoc);
var revNodes = myhtmlDoc.DocumentNode
.Descendants("div")
.Where(x => x.Attributes["data-group"] != null && x.Attributes["data-group"].Value.Contains("Revision") == true)
.ToList<HtmlNode>();
foreach (HtmlNode node in myhtmlDoc.DocumentNode.Descendants("div"))
{
foreach (HtmlNode revNode in revNodes)
{
if (node == revNode)
{
var test = node.SelectNodes("//div[2]//table//tr");
//foreach (HtmlNode row in test.Nodes)
foreach (HtmlNode row in node.SelectNodes("//div//div[2]//table//tr"))
{
if (row.SelectSingleNode("td[1]") != null)
row.RemoveChild(row.SelectSingleNode("td[1]"));
if (row.SelectSingleNode("td[2]") != null)
row.RemoveChild(row.SelectSingleNode("td[2]"));
if (row.SelectSingleNode("th[1]") != null)
row.RemoveChild(row.SelectSingleNode("th[1]"));
if (row.SelectSingleNode("th[2]") != null)
row.RemoveChild(row.SelectSingleNode("th[2]"));
// row.RemoveChild(row.SelectSingleNode("td[8]"));
}
}
}
}
myhtmlDoc.Save(#"D:\REsult.html")

Assuming you have a context node and you want to select a child div or table use the path div respectively div/table. If you start your path with //div respectively //div/table your selection starts down from the root node of the context node, that is, it searches the whole document. So make sure you use a relative path, if you look for descendants then use .//div or .//div/table but not //div/table as that way you search the whole document of the context node and not the subtree of the context node.

Related

Python multiple if statements for petrol price movement

Situation:
I buy a certain volume of petrol at price X, which is usually sold within a 30 days. During these 30 days, I will need to adjust my petrol station gas price according to average State gas price. If State price goes up by 1.2% from my purchased price, I will set my price to +1% of my purchased price.
Here is an example:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-wa1i{font-weight:bold;text-align:center;vertical-align:middle}
.tg .tg-7zrl{text-align:left;vertical-align:bottom}
.tg .tg-0lax{text-align:left;vertical-align:top}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-wa1i">Time</th>
<th class="tg-wa1i">Average state gas price</th>
<th class="tg-wa1i">Av state price change, %</th>
<th class="tg-wa1i">My price change, %</th>
<th class="tg-wa1i">My station gas price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-7zrl">1</td>
<td class="tg-0lax"> 4.231 </td>
<td class="tg-0lax"> - </td>
<td class="tg-0lax"> - </td>
<td class="tg-0lax"> 4.231 </td>
</tr>
<tr>
<td class="tg-7zrl">2</td>
<td class="tg-0lax"> 4.337 </td>
<td class="tg-0lax"> 2.5%</td>
<td class="tg-0lax"> 2.0%</td>
<td class="tg-0lax"> 4.316 </td>
</tr>
<tr>
<td class="tg-7zrl">3</td>
<td class="tg-0lax"> 4.437 </td>
<td class="tg-0lax"> 4.9%</td>
<td class="tg-0lax"> 4.0%</td>
<td class="tg-0lax"> 4.400 </td>
</tr>
<tr>
<td class="tg-7zrl">4</td>
<td class="tg-0lax"> 4.481 </td>
<td class="tg-0lax"> 5.9%</td>
<td class="tg-0lax"> 5.0%</td>
<td class="tg-0lax"> 4.443 </td>
</tr>
<tr>
<td class="tg-7zrl">5</td>
<td class="tg-0lax"> 4.571 </td>
<td class="tg-0lax"> 8.0%</td>
<td class="tg-0lax"> 8.0%</td>
<td class="tg-0lax"> 4.569 </td>
</tr>
<tr>
<td class="tg-7zrl">6</td>
<td class="tg-0lax"> 4.616 </td>
<td class="tg-0lax"> 9.1%</td>
<td class="tg-0lax"> 9.0%</td>
<td class="tg-0lax"> 4.612 </td>
</tr>
<tr>
<td class="tg-7zrl">7</td>
<td class="tg-0lax"> 4.709 </td>
<td class="tg-0lax"> 11.3%</td>
<td class="tg-0lax"> 11.0%</td>
<td class="tg-0lax"> 4.696 </td>
</tr>
<tr>
<td class="tg-7zrl">8</td>
<td class="tg-0lax"> 4.850 </td>
<td class="tg-0lax"> 14.6%</td>
<td class="tg-0lax"> 14.0%</td>
<td class="tg-0lax"> 4.823 </td>
</tr>
</tbody>
</table>
Here is a python code but it is very clunky, and if gas price moves up by 20%, then I have to write my_priceX up to 20 times. Is there a more elegant solution?
my_price1 = last_gas_price["price"]*1.01
my_price2 = last_gas_price["price"]*1.02
my_price3 = last_gas_price["price"]*1.03
my_price4 = last_gas_price["price"]*1.04
my_price5 = last_gas_price["price"]*1.05
if last_gas_price > my_price1:
adj_price(price = my_price1)
if last_gas_price > my_price2:
adj_price(price = my_price2)
if last_gas_price > my_price3:
adj_price(price = my_price3)
if last_gas_price > my_price4:
adj_price(price = my_price4)
if last_gas_price > my_price5:
adj_price(price = my_price5)

I used Python Selenium to choose a "Year" from the dropdown box, clicked "search," and it apparently worked. But the data says otherwise

There is a page with tables of statistics I'm trying to pull.
The page has the default year as 2020, with a dropdown box to select different years. I wrote this code to select 2009.
from selenium import webdriver as wd
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from pandas.io.html import read_html
from selenium.webdriver.support.ui import Select
import numpy as np
import re
import pandas as pd
driver=wd.Chrome()
driver.implicitly_wait(10)
driver.get('https://www.cpbl.com.tw/standings/history')
select = Select(driver.find_element_by_id('Year'))
# select by visible text
select.select_by_visible_text('2009')
button = driver.find_elements_by_xpath("//input[#value='查詢']")[0]
button.click()
main=driver.find_elements_by_xpath('//*[(#id = "PageListContainer")]')[0]
main_att=main.get_attribute('innerHTML')
tab=pd.read_html(main_att)
I purposely didn't say driver.close() to leave the browser open, so I can look at it, and apparently the selection of 2009 worked. The browser had tables for 2009. However, the data my code pulled was still from the default year (2020). I want data from 2009. Anyone know why?
I am using Python 3.7 and Spyder 4.0.1
To select 2009 from the html-select and extract the innerHTML of the PageListContainer you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver.get("https://www.cpbl.com.tw/standings/history")
Select(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "select#Year")))).select_by_visible_text("2009")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#value='查詢']"))).click()
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[#id = 'PageListContainer']"))).get_attribute("innerHTML"))
Console Output:
<!--上半季戰績-->
<div class="RecordTableWrap">
<div class="record_table_caption">上半季戰績</div>
<div class="record_table_swipe_guide" style="display: none;">
<div class="desktop"></div>
<div class="mobile"></div>
</div>
<div class="record_table_scroll_ctrl" style="display: none;">
</div>
<div class="RecordTableOuter">
<div class="RecordTable">
<table>
<tbody><tr>
<th class="sticky">
<div class="sticky_wrap">
<div class="rank">排名</div>
<div class="team-w-trophy">球隊</div>
</div>
</th>
<th class="num">出賽數</th>
<th class="num">勝-和-敗</th>
<th class="num">勝率</th>
<th class="num">勝差</th>
<th class="num">中信兄弟</th>
<th class="num">樂天桃猿</th>
<th class="num">統一7-ELEVEn獅</th>
<th class="num">富邦悍將</th>
<th class="num">主場戰績</th>
<th class="num">客場戰績</th>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">1</div>
<div class="team-w-trophy">
中信兄弟
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">37-0-23</td>
<td class="num">0.617</td>
<td class="num">-</td>
<td class="num"> </td>
<td class="num">8-0-12</td>
<td class="num">16-0-4</td>
<td class="num">13-0-7</td>
<td class="num">18-0-12</td>
<td class="num">19-0-11</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">2</div>
<div class="team-w-trophy">
樂天桃猿
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">34-0-26</td>
<td class="num">0.567</td>
<td class="num">3</td>
<td class="num">12-0-8</td>
<td class="num"> </td>
<td class="num">9-0-11</td>
<td class="num">13-0-7</td>
<td class="num">18-0-12</td>
<td class="num">16-0-14</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">3</div>
<div class="team-w-trophy">
統一7-ELEVEn獅
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">26-0-34</td>
<td class="num">0.433</td>
<td class="num">11</td>
<td class="num">4-0-16</td>
<td class="num">11-0-9</td>
<td class="num"> </td>
<td class="num">11-0-9</td>
<td class="num">13-0-17</td>
<td class="num">13-0-17</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">4</div>
<div class="team-w-trophy">
富邦悍將
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">23-0-37</td>
<td class="num">0.383</td>
<td class="num">14</td>
<td class="num">7-0-13</td>
<td class="num">7-0-13</td>
<td class="num">9-0-11</td>
<td class="num"> </td>
<td class="num">13-0-17</td>
<td class="num">10-0-20</td>
</tr>
</tbody></table>
</div>
</div>
</div>
<!--上半季戰績 end-->
<!--下半季戰績-->
<div class="RecordTableWrap">
<div class="record_table_caption">下半季戰績</div>
<div class="record_table_swipe_guide" style="display: none;">
<div class="desktop"></div>
<div class="mobile"></div>
</div>
<div class="record_table_scroll_ctrl" style="display: none;">
</div>
<div class="RecordTableOuter">
<div class="RecordTable">
<table>
<tbody><tr>
<th class="sticky">
<div class="sticky_wrap">
<div class="rank">排名</div>
<div class="team-w-trophy">球隊</div>
</div>
</th>
<th class="num">出賽數</th>
<th class="num">勝-和-敗</th>
<th class="num">勝率</th>
<th class="num">勝差</th>
<th class="num">中信兄弟</th>
<th class="num">樂天桃猿</th>
<th class="num">統一7-ELEVEn獅</th>
<th class="num">富邦悍將</th>
<th class="num">主場戰績</th>
<th class="num">客場戰績</th>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">1</div>
<div class="team-w-trophy">
統一7-ELEVEn獅
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">32-1-27</td>
<td class="num">0.542</td>
<td class="num">-</td>
<td class="num">13-1-6</td>
<td class="num">10-0-10</td>
<td class="num"> </td>
<td class="num">9-0-11</td>
<td class="num">16-0-14</td>
<td class="num">16-1-13</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">2</div>
<div class="team-w-trophy">
富邦悍將
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">31-1-28</td>
<td class="num">0.525</td>
<td class="num">1</td>
<td class="num">9-1-10</td>
<td class="num">11-0-9</td>
<td class="num">11-0-9</td>
<td class="num"> </td>
<td class="num">15-1-14</td>
<td class="num">16-0-14</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">3</div>
<div class="team-w-trophy">
中信兄弟
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">30-2-28</td>
<td class="num">0.517</td>
<td class="num">1.5</td>
<td class="num"> </td>
<td class="num">14-0-6</td>
<td class="num">6-1-13</td>
<td class="num">10-1-9</td>
<td class="num">16-1-13</td>
<td class="num">14-1-15</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">4</div>
<div class="team-w-trophy">
樂天桃猿
</div>
</div>
</td>
<td class="num">60</td>
<td class="num">25-0-35</td>
<td class="num">0.417</td>
<td class="num">7.5</td>
<td class="num">6-0-14</td>
<td class="num"> </td>
<td class="num">10-0-10</td>
<td class="num">9-0-11</td>
<td class="num">16-0-14</td>
<td class="num">9-0-21</td>
</tr>
</tbody></table>
</div>
</div>
</div>
<!--下半季戰績 end-->
<!--全年戰績-->
<div class="RecordTableWrap">
<div class="record_table_caption">全年戰績</div>
<div class="record_table_swipe_guide" style="display: none;">
<div class="desktop"></div>
<div class="mobile"></div>
</div>
<div class="record_table_scroll_ctrl" style="display: none;">
</div>
<div class="RecordTableOuter">
<div class="RecordTable">
<table>
<tbody><tr>
<th class="sticky">
<div class="sticky_wrap">
<div class="rank">排名</div>
<div class="team-w-trophy">球隊</div>
</div>
</th>
<th class="num">出賽數</th>
<th class="num">勝-和-敗</th>
<th class="num">勝率</th>
<th class="num">勝差</th>
<th class="num">中信兄弟</th>
<th class="num">樂天桃猿</th>
<th class="num">統一7-ELEVEn獅</th>
<th class="num">富邦悍將</th>
<th class="num">主場戰績</th>
<th class="num">客場戰績</th>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">1</div>
<div class="team-w-trophy">
中信兄弟
</div>
</div>
</td>
<td class="num">120</td>
<td class="num">67-2-51</td>
<td class="num">0.568</td>
<td class="num">-</td>
<td class="num"> </td>
<td class="num">22-0-18</td>
<td class="num">22-1-17</td>
<td class="num">23-1-16</td>
<td class="num">34-1-25</td>
<td class="num">33-1-26</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">2</div>
<div class="team-w-trophy">
樂天桃猿
</div>
</div>
</td>
<td class="num">120</td>
<td class="num">59-0-61</td>
<td class="num">0.492</td>
<td class="num">9</td>
<td class="num">18-0-22</td>
<td class="num"> </td>
<td class="num">19-0-21</td>
<td class="num">22-0-18</td>
<td class="num">34-0-26</td>
<td class="num">25-0-35</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">3</div>
<div class="team-w-trophy">
統一7-ELEVEn獅
</div>
</div>
</td>
<td class="num">120</td>
<td class="num">58-1-61</td>
<td class="num">0.487</td>
<td class="num">9.5</td>
<td class="num">17-1-22</td>
<td class="num">21-0-19</td>
<td class="num"> </td>
<td class="num">20-0-20</td>
<td class="num">29-0-31</td>
<td class="num">29-1-30</td>
</tr>
<tr>
<td class="sticky">
<div class="sticky_wrap">
<div class="rank">4</div>
<div class="team-w-trophy">
富邦悍將
</div>
</div>
</td>
<td class="num">120</td>
<td class="num">54-1-65</td>
<td class="num">0.454</td>
<td class="num">13.5</td>
<td class="num">16-1-23</td>
<td class="num">18-0-22</td>
<td class="num">20-0-20</td>
<td class="num"> </td>
<td class="num">28-1-31</td>
<td class="num">26-0-34</td>
</tr>
</tbody></table>
</div>
</div>
</div>
<!--全年戰績 end-->
It worked when I used time.sleep(10)

How to make an item always appear last on list (Netsuite Advanced PDF)

I am trying to make an item appear last on the list if it appears on an in the invoice (Advanced PDF,NetSuite).
I was thinking bout trying to sort by and adding some ZZZs to the item name, but thats because I dont really know much outside of basic HTML.
Any Help would be appreciated.
Below is the table code I am dealing with.
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th align="center" colspan="3">${item.quantity#label}</th>
<th colspan="12">${item.item#label}</th>
<th colspan="3">${item.options#label}</th>
<th align="right" colspan="4">${item.rate#label}</th>
<th align="right" colspan="4">${item.amount#label}</th>
</tr>
</thead>
</#if><tr>
<td align="center" colspan="3" line-height="150%">${item.quantity}</td>
<td colspan="12"><span class="itemname">${item.item}</span><br />${item.description}</td>
<td colspan="3">${item.options}</td>
<td align="right" colspan="4">${item.rate}</td>
<td align="right" colspan="4">${item.amount}</td>
</tr>
</#list>
I need the to be able to choose a specific itemname to always show at the bottom.
You can use the assign tag to hold the values for your bottom item.
<#assign bottomItemName = 'Bottom Item Name'>
<#assign bottomItem = {}>
<#list record.item as item>
<#if item_index==0>
<thead>
<tr>
<th align="center" colspan="3">${item.quantity#label}</th>
<th colspan="12">${item.item#label}</th>
<th colspan="3">${item.options#label}</th>
<th align="right" colspan="4">${item.rate#label}</th>
<th align="right" colspan="4">${item.amount#label}</th>
</tr>
</thead>
</#if>
<#if item.item == bottomItemName>
<#assign bottomItem = bottomItem + item>
<#else>
<tr>
<td align="center" colspan="3" line-height="150%">${item.quantity}</td>
<td colspan="12"><span class="itemname">${item.item}</span><br />${item.description}</td>
<td colspan="3">${item.options}</td>
<td align="right" colspan="4">${item.rate}</td>
<td align="right" colspan="4">${item.amount}</td>
</tr>
</#if>
</#list>
<#if bottomItem.item??>
<tr>
<td align="center" colspan="3" line-height="150%">${bottomItem.quantity}</td>
<td colspan="12"><span class="itemname">${bottomItem.item}</span><br />${bottomItem.description}</td>
<td colspan="3">${bottomItem.options}</td>
<td align="right" colspan="4">${bottomItem.rate}</td>
<td align="right" colspan="4">${bottomItem.amount}</td>
</tr>
</#if>
You could try looping 2x.
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th align="center" colspan="3">${item.quantity#label}</th>
<th colspan="12">${item.item#label}</th>
<th colspan="3">${item.options#label}</th>
<th align="right" colspan="4">${item.rate#label}</th>
<th align="right" colspan="4">${item.amount#label}</th>
</tr>
</thead>
</#if><#if ${item.item}!="Your Item"><tr>
<td align="center" colspan="3" line-height="150%">${item.quantity}</td>
<td colspan="12"><span class="itemname">${item.item}</span><br />${item.description}</td>
<td colspan="3">${item.options}</td>
<td align="right" colspan="4">${item.rate}</td>
<td align="right" colspan="4">${item.amount}</td>
</tr>
</#list>
<#list record.item as item><#if ${item.item}=="Your Item"><tr>
<td align="center" colspan="3" line-height="150%">${item.quantity}</td>
<td colspan="12"><span class="itemname">${item.item}</span><br />${item.description}</td>
<td colspan="3">${item.options}</td>
<td align="right" colspan="4">${item.rate}</td>
<td align="right" colspan="4">${item.amount}</td>
</tr>
</#list>
I haven't tested the if statement, so good luck

How to you print one Result on the Advanced PDF Template from a Saved Search vs a list?

I have an Inbound Shipment saved search of items coming in listed by container. I have no problem printing the list of the items with quantities, description, etc. but when I add in the "vessel Number" or "shipment number" I don't need it to repeat on every line. I would prefer to show the information that I would normally "group" at the top of the PDF vs. on each line.
I should note that when I print the saved search, I would have already filtered the search down to one container, meaning only one "shipment number" and one "vessel number".
<table align="center" border=".5" cellpadding=".5" cellspacing=".5" class="NATIVE-TABLE" style="width:100%;"><#list results as result><#if result_index == 0>
<thead>
<tr>
<th align="center" scope="col" style="width: 107px;">
<div><big>Shipment #</big></div>
</th>
<th align="center" scope="col" style="width: 103px;">
<div><big>Status</big></div>
</th>
<th align="center" scope="col" style="width: 156px;">
<div><big>Destination</big></div>
</th>
<th align="center" scope="col" style="width: 150px;">
<div><big>Actual Ship Date</big></div>
</th>
<th align="center" scope="col" style="width: 154px;">
<div><big>Expected Delivery Date</big></div>
</th>
<th align="center" scope="col">
<div><big>Carrier</big></div>
</th>
<th align="center" scope="col">
<div><big>Vessel #</big></div>
</th>
</tr>
</thead>
</#if><tr>
<td align="center" style="width: 107px;">${result.shipmentnumber}</td>
<td align="center" style="width: 103px;">${result.status}</td>
<td align="center" style="width: 156px;">${result.custrecord142}</td>
<td align="center" style="width: 150px;">${result.actualshippingdate}</td>
<td align="center" style="width: 154px;">${result.expecteddeliverydate}</td>
<td align="center" style="width: 154px;">${result.custrecord_htd_shipper_info}</td>
<td align="center" style="width: 154px;">${result.vesselnumber}</td>
</tr>
</#list></table>
First: please post your code so we can see where you're up to and respond accordingly - it helps us to help you!
Second: The general pattern would be that you simply use values from the first result to make up your header, and then iterate through all results to give your lines. It would look something like:
<#list results as result>
<#if result_index == 0>
*header information goes here*
</#if>
*line information goes here*
</#list>
Edited to add code
<table align="center" border=".5" cellpadding=".5" cellspacing=".5" class="NATIVE-TABLE" style="width:100%;"><#list results as result><#if result_index == 0>
<thead>
<tr>
<th align="center" scope="col" style="width: 107px;">
<div><big>Shipment #</big></div>
</th>
<th align="center" scope="col" style="width: 103px;">
<div><big>Status</big></div>
</th>
<th align="center" scope="col" style="width: 156px;">
<div><big>Destination</big></div>
</th>
<th align="center" scope="col" style="width: 150px;">
<div><big>Actual Ship Date</big></div>
</th>
<th align="center" scope="col" style="width: 154px;">
<div><big>Expected Delivery Date</big></div>
</th>
<th align="center" scope="col">
<div><big>Carrier</big></div>
</th>
<th align="center" scope="col">
<div><big>Vessel #</big></div>
</th>
</tr>
</thead>
<tr>
<td align="center" style="width: 107px;">${result.shipmentnumber}</td>
<td align="center" style="width: 103px;">${result.status}</td>
<td align="center" style="width: 156px;">${result.custrecord142}</td>
<td align="center" style="width: 150px;">${result.actualshippingdate}</td>
<td align="center" style="width: 154px;">${result.expecteddeliverydate}</td>
<td align="center" style="width: 154px;">${result.custrecord_htd_shipper_info}</td>
<td align="center" style="width: 154px;">${result.vesselnumber}</td>
</tr>
</#if>
<tr>
<td align="center" style="width: 107px;"></td>
<td align="center" style="width: 103px;">${result.status}</td>
<td align="center" style="width: 156px;">${result.custrecord142}</td>
<td align="center" style="width: 150px;">${result.actualshippingdate}</td>
<td align="center" style="width: 154px;">${result.expecteddeliverydate}</td>
<td align="center" style="width: 154px;">${result.custrecord_htd_shipper_info}</td>
<td align="center" style="width: 154px;"></td>
</tr>
</#list>
</table>

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]]

Resources