I'm working in the chrome dev tools console trying to get the attribute value of data-label.
<thead>
<tr>
<th id="gv-field-1-id" class="gv-field-1-id" style="width:5%;" data-label="#"><span class="gv-field-label"> #</span></th><th id="gv-field-1-date_created" class="gv-field-1-date_created" style="width:7%;" data-label="Date"><span class="gv-field-label"> Date</span></th><th id="gv-field-1-99.2" class="gv-field-1-99.2" data-label="County"><span class="gv-field-label"> County</span></th><th id="gv-field-1-99.1" class="gv-field-1-99.1" style="width:14%;" data-label="State"><span class="gv-field-label"> State</span></th><th id="gv-field-1-5" class="gv-field-1-5" style="width:7%;" data-label="Acres"><span class="gv-field-label"> Acres</span></th><th id="gv-field-1-13" class="gv-field-1-13" data-label="Name"><span class="gv-field-label"> Name</span></th><th id="gv-field-1-23" class="gv-field-1-23" style="width:8%;" data-label="Ask $"><span class="gv-field-label"> Ask $</span></th><th id="gv-field-1-122" class="gv-field-1-122" style="width:8%;" data-label="New $"><span class="gv-field-label"> New $</span></th><th id="gv-field-1-123" class="gv-field-1-123" style="width:8%;" data-label="Assd $"><span class="gv-field-label"> Assd $</span></th><th id="gv-field-1-26" class="gv-field-1-26" data-label="Eager"><span class="gv-field-label"> Eager</span></th> </tr>
</thead>
The closest I can get to the value (Date in this case) is
$x('//th[contains(#id,"gv-field")]/#data-label')
How can I get the attribute value here?
You can do :
$x('string(//th[contains(#id,"gv-field")]/#data-label)')
Related
I am trying to add text above every column in Colspan but nothing works as expected.
https://i.stack.imgur.com/MxQPj.png as shown here in the image I want in columns of colspan to be
1 2 3 4 5 O, but I don't know how to make that.
Here is example of my code
<thead>
<tr>
<th width="30%">
#DbResHtml.T("Натпреварувач", "Resources")
</th>
<th width="1%">
#DbResHtml.T("Бр.", "Resources")
</th>
<th width="1%">#DbResHtml.T("ВИ", "Resources")</th>
<th width="1%">
#DbResHtml.T("П.", "Resources")
</th>
<th colspan="6" scope="colgroup">
#DbResHtml.T("Грешки", "Resources")<br>
#DbResHtml.T("12345O", "Resources")
</th>
</tr>
</thead>
Tbody code is not included for clarity.
I'm not sure if I'm following your question correctly, but if you want text above each column a colspan will prevent that from working correctly. You would need to split them into their own elements.
<thead>
<tr>
<th width="30%">
#DbResHtml.T("Натпреварувач", "Resources")
</th>
<th width="1%">
#DbResHtml.T("Бр.", "Resources")
</th>
<th width="1%">#DbResHtml.T("ВИ", "Resources")</th>
<th width="1%">
#DbResHtml.T("П.", "Resources")
</th>
<th>#DbResHtml.T("Г", "Resources") <br>
#DbResHtml.T("1", "Resources")
</th>
<th>#DbResHtml.T("р", "Resources")<br>
#DbResHtml.T("2", "Resources")</th>
<th>#DbResHtml.T("е", "Resources")<br>
#DbResHtml.T("3", "Resources")</th>
<th>#DbResHtml.T("ш", "Resources")<br>
#DbResHtml.T("4", "Resources")</th>
<th>#DbResHtml.T("к", "Resources")<br>
#DbResHtml.T("5", "Resources")</th>
<th>#DbResHtml.T("и", "Resources")<br>
#DbResHtml.T("O", "Resources")</th>
</tr>
</thead>
As it appears you are pulling from a Db so you could split the strings into arrays and perform a loop to generate each for each character in the array.
Hope this helps.
I am new to Powershell, and I suck at html.
There's a page with a table, and each cell has a ahref link, the value of the link is dynamic, but the link which I want to automate-clicking is always in the first cell.
I know there's cellindex in html/JS, is it usable in PS?
For example, let's say I have this table on a website.
<table>
<tr>
<td>
<a href="http://example1.com">
<div style="height:100%;width:100%">
hello world1
</div>
</a>
</td>
</tr>
<tr>
<td>
<a href="http://example2.com">
<div style="height:100%;width:100%">
hello world2
</div>
</a>
</td>
</tr>
<tr>
<td>
<a href="http://example3.com">
<div style="height:100%;width:100%">
hello world3
</div>
</a>
</td>
</tr>
</table>
And I want to make powershell to always click on the first link, the link inside is dynamic though.
Any ideas? Hints?
The result of Invoke-WebRequest returns a property named Links that is a collection of all the hyperlinks on a web page.
For example:
$Web = Invoke-webrequest -Uri 'http://wragg.io' $Web.Links | Select innertext,href
Returns:
innerText href
--------- ----
Mark Wragg http://wragg.io
Twitter https://twitter.com/markwragg
Github https://github.com/markwragg
LinkedIn https://uk.linkedin.com/in/mwragg
If the link you want to capture is always the first in this list you could get it by doing:
$Web.Links[0].href
If it's the second [1], third [2] etc. etc.
I don't think there is an equivalent of "cellindex", although there is a property named AllElements that you can access via an array index. E.g if you wanted the second element on the page you could for example do:
$Web.AllElements[2]
If you need to get to a specific table in the page and then access links inside of that table you'd probably need to iterate through the AllElements property until you reached the table you wanted. For example if you know the links were in the third table on the page:
$Links = #()
$TableCount = 0
$Web.AllElements | ForEach-Object {
If ($_.tagname -eq 'table'){ $TableCount++ }
If ($TableCount -eq 3){
If ($_.tagname -eq 'a') {
$Links += $_
}
}
}
$Links | Select -First 1
Ok, the Invoke-webrequest method is working with mark's link but with my page; but I noticed a pattern that may can be used:
I noticed the the following:
<table id="row" class="simple">
<thead>
<tr>
<th></th>
<th class="centerjustify">File Name</th>
<th class="centerjustify">File ID</th>
<th class="datetime">Creation Date</th>
<th class="datetime">Upload Date</th>
<th class="centerjustify">Processing Status</th>
<th class="centerjustify">Exceptions</th>
<th class="centerjustify">Unprocessed Count</th>
<th class="centerjustify">Discarded Count</th>
<th class="centerjustify">Rejected Count</th>
<th class="centerjustify">Void Count</th>
<th class="centerjustify">PO Total Count</th>
<th class="centerjustify">PO Total Amount</th>
<th class="centerjustify">CM Total Count</th>
<th class="centerjustify">CM Total Amount</th>
<th class="centerjustify">PO Processed Count</th>
<th class="centerjustify">PO Processed Amount</th>
<th class="centerjustify">CM Processed Count</th>
<th class="centerjustify">CM Processed Amount</th>
<th class="centerjustify">Counts At Upload</th></tr></thead>
<tbody>
<tr class="odd">
<td><input type="radio" disabled="disabled" name="checkedValue" value="12047" /></td>
<td class="leftjustify textColorBlack">
520170123000000_520170123000000_20170327_01.txt</td>
<td class="centerjustify textColorBlack">1</td>
<td class="datetime textColorBlack">Mar 27, 2017 0:00</td>
<td class="datetime textColorBlack">Mar 27, 2017 10:33:24 PM +03:00</td>
<td class="centerjustify textColorBlack">
The fId part in "loadConfirmationDetails.htm?fId=12047" is dynamic; and it's the last part of the next page;
For example: "https://aaa.xxxxxxx.com/aaa/community/loadConfirmationDetails.htm?fId=12047
And table's ID is unique, called "row" - I wonder if I can use a completely another way; other than invoking the webpage, by auto-copying this id info from its source html and concatenate it with the main link?
I am really out of ideas beyond that.
I am creating a table and I would like to show and hide individual columns. What I could not achieve is that all columns appear and the user can show or hide the like.
<table border="0" id="proforma" data-role="table" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-button-theme="b" data-column-btn-theme="b" data-column-btn-text="Ver más" data-column-popup-theme="b">
<thead>
<tr class="ui-bar-d">
<th class="header_table cliente_table">Cliente</th>
<th class="header_table real_table">Real (%)</th>
<th class="header_table proy_table">Proy (%)</th>
<th class="header_table falta_table">Falta (M$)</th>
<th class="header_table cod_table" data-priority="5">Código</th>
<th class="header_table dato_table" data-priority="6">Dirección</th>
</tr>
</thead>
</table>
Of these 6 columns I would like to appear for the first time the first 4, the last two always hidden. But by pressing the button to show / hide, appear also the first 4 to give the user the option that is not what I could get.
Only columns with a data priority are included in the toggle list, so add a data-priority of 1 to the first four columns:
<table border="0" id="proforma" data-role="table" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-button-theme="b" data-column-btn-theme="b" data-column-btn-text="Ver más" data-column-popup-theme="b">
<thead>
<tr class="ui-bar-d">
<th class="header_table cliente_table" data-priority="1">Cliente</th>
<th class="header_table real_table" data-priority="1">Real (%)</th>
<th class="header_table proy_table" data-priority="1">Proy (%)</th>
<th class="header_table falta_table" data-priority="1">Falta (M$)</th>
<th class="header_table cod_table" data-priority="5">Código</th>
<th class="header_table dato_table" data-priority="6">Dirección</th>
</tr>
</thead>
</table>
How do I get all the links in a table based on the table caption?
<table class="wikitable sortable plainrowheaders">
<caption>Film</caption>
<tr>
<th scope="col">Year</th>
<th scope="col">Title</th>
<th scope="col">Role</th>
<th scope="col" class="unsortable">Notes</th>
</tr>
<tr>
<td style="text-align:center;">1997</td>
<th scope="row"><i><span class="sortkey">Ice Storm, The</span><span class="vcard"><span class="fn">The Ice Storm</span> </span></i></th>
<td>Libbets Casey</td>
<td>First professional role</td>
</tr>
</table>
I tried this
doc = Nokogiri::HTML(str)
doc.xpath('//table[caption=''Film'']//a/#href').each do |href|
p href
end
But this doesn't print anything.
You can write your code as below :-
require 'nokogiri'
doc = Nokogiri::HTML::Document.parse <<-EOT
<table class="wikitable sortable plainrowheaders">
<caption>Film</caption>
<tr>
<th scope="col">Year</th>
<th scope="col">Title</th>
<th scope="col">Role</th>
<th scope="col" class="unsortable">Notes</th>
</tr>
<tr>
<td style="text-align:center;">1997</td>
<th scope="row"><i><span class="sortkey">Ice Storm, The</span><span class="vcard"><span class="fn">The Ice Storm</span> </span></i></th>
<td>Libbets Casey</td>
<td>First professional role</td>
</tr>
</table>
EOT
doc.xpath("//table[./caption[text()='Film']]//a").each do |node|
p node['href']
end
# >> "/wiki/The_Ice_Storm_(film)"
I'm returning a list generated form a csv file in an html table format:
<span class="gwt-HTML">
<div id="productList">
nullnullnullnullnull
<table cellspacing="0">
<tbody>
<tr>
<th>Type Name</th>
<th>Class Name</th>
<th>Sub Class Name</th>
<th>Minor Class Name</th>
<th>Country Origin</th>
<th>SKU</th>
etc..
Notice the weird nullnullnullnullnull showing up? This happens when after the html gets converted into the widget:
SimplePanel pnl = new SimplePanel();
HTML res = new HTML(result);
pnl.add(res);
RootPanel.get("tableData").add(pnl);
The result variable is the html string:
<div id="productList">
<table cellspacing="0">
<tbody>
<tr>
<th>Type Name</th>
<th>Class Name</th>
<th>Sub Class Name</th>
<th>Minor Class Name</th>
<th>Country Origin</th>
<th>SKU</th>
...etc
I've checked to make sure the result String does not contain the null's. Anybody have an idea as to why this is happening? Very strange...