I am super new to KM.
I have a table in a website, it usually has 4 rows but sometimes 1 of them is missing and then has only 3 rows, or may have only 1 row…
then the JS path changes and my macro does not work.
Table when it has all 4 counties:
If all 4 counties are present the JS for HAWAII Sales is always the same: document.querySelector("
#expected-wholesale-locals > tbody > tr:nth-child(3) > td.wholesale-sales.text-right > span")
But if there's only 1 or 2 counties it changes to :
#expected-wholesale-locals > tbody > tr:nth-child(1) > td.wholesale-sales.text-right > span") or
#expected-wholesale-locals > tbody > tr:nth-child(2) > td.wholesale-sales.text-right > span")
Depending on what rows if falls... How can I fix this? Is there a way to say instead copy B if A reads "HAWAII"?
Some HTML coding:
I'd suggest basically you need to read the left column of each successive row until you find one that is
HAWAII COUNTY and then read the right column.
For each n in number rang 1…10
Read innerText of the n’th row’s first column
If the innerText is “HAWAII COUNTY” then
Read the innerText of the n’th row’s fourth column, and break from the for each loop
Thank you so much!!!
Can you give us the URL to the actual web page where the table resides?
The website is not public, you need a login info to access. But I found this website with a table that may serve the same purpose!!!
This article lists the 3,243 counties and county equivalents of the United States.[a] The 50 states of the United States are divided into 3,007 counties, political and geographic subdivisions of a state; 236 other local governments and geographic places are also first-order administrative divisions of their respective state/district/territory, but are called by different names. The latter are referred to collectively as county equivalents by the United States Census Bureau. The 236 count Among ...
I would need a macro that copies column C if Column A value is Blount, but JS path is not always the same, it varies depending on how many counties there are listed before Blount...
How do I create a macro that says if Column A reads Blount go to Column C and copy that value to the system clipboard?
I appreciate your help!!!!
You can make this task pretty complex, or you can boil it down into something reasonably simple.
The first macro below extracts the innerText of the entire table and then uses Keyboard Maestro's
Search Variable action to parse for a row that starts with "Blount".
The working regular expression looks for:
If that's found the entire line will be returned.
Only the first instance is searched for in this macro – other instances will be ignored.
You can easily parse the rest from there.
If you need to get all lines that start with "Blount" then you have to jump through another couple of hoops using native Keyboard Maestro actions, but it's not overly difficult.
Extract Text From Web Table v1.00.kmmacros (8.0 KB)
I reckon you could also loop through the lines of the table-object and use a regex filter to find any relevant rows, but I don't want to fool with that right now.
This general methodology keeps you from having to use a hard path to the table row you're looking for.
It should also be possible to use XPath and a specifier to look for a row beginning with certain content in a certain table – but that's beyond me at the moment, and I don't want to spend time figuring it out.
@ComplexPoint ought to be able to pull this out of his hat though...