IMacros + XPATH:Count children of tag

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
peppe1
Posts: 11
Joined: Fri Mar 04, 2016 7:32 pm

IMacros + XPATH:Count children of tag

Post by peppe1 » Wed Aug 03, 2016 9:48 am

Hey guys,

I have a quick question related to using XPATH with Imacros. I am trying to count how many <tr> tags are inside a <tbody>
I am currently using IMacros V11.1.495.5175, Firefox 47.0.1, Windows 7 German.

My current code looks like this:

var test_xpath = "//table[@class='tableProduct']/tbody/select=count(tr)";
var test_macro = "CODE: TAG XPATH=" + '"' + test_xpath + '"' + " EXTRACT=TXT" + "\n";
test_macro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=*" + "\n";
iimPlay(test_macro);
alert(iimGetLastExtract());//this should give me the number of <tr> inside the <tbody>...but it's not giving me anything

This information is used in a for loop that will extract more information from each <tr>. I just want to know how many times I need to loop it.
Any help is greatly appreciated.

Thank you !
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: IMacros + XPATH:Count children of tag

Post by chivracq » Wed Aug 03, 2016 10:49 am

peppe1 wrote:Hey guys,

I have a quick question related to using XPATH with Imacros. I am trying to count how many <tr> tags are inside a <tbody>
I am currently using

Code: Select all

IMacros V11.1.495.5175, Firefox 47.0.1, Windows 7 German.
My current code looks like this:

Code: Select all

var test_xpath = "//table[@class='tableProduct']/tbody/select=count(tr)";
var test_macro = "CODE: TAG XPATH=" + '"' + test_xpath + '"' + " EXTRACT=TXT" + "\n";
test_macro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=*" + "\n";
iimPlay(test_macro);
alert(iimGetLastExtract());//this should give me the number of <tr> inside the <tbody>...but it's not giving me anything
This information is used in a for loop that will extract more information from each <tr>. I just want to know how many times I need to loop it.
Any help is greatly appreciated.

Thank you !
Duplicate Thread: :mrgreen:
- IMacros + XPATH:Count children of tag
COSMOS wrote:Hey guys !

I have a brief question related more to XPATH.
I am using imacros with javascript to build a search script.
I am using CODE: TAG XPATH= .. in order to get to a certain <tbody> on a page.
What I want is to do a count of all the <tr> inside this tbody.

My current script looks like this:

Code: Select all

var test_xpath = "//table[@class='tableProduct']/tbody/select=count(tr)";
var test_macro = "CODE: TAG XPATH=" + '"' + test_xpath + '"' + " EXTRACT=TXT" + "\n"; 
iimPlay(test_macro);
alert(iimGetLastExtract()); //This should give me the number of <tr> inside the <tbody>
//Using this information I can do a for loop in js which would extract further information inside each <tr> 
I am just learning xpath so I'll continue to look around but I wanted to ask you guys maybe someone can help.
To be in accordance with the forums posting policy I'm supplying my configuration: (even if it's not really related)

Code: Select all

1. What version of iMacros are you using?
VERSION BUILD=11.1.495.5175 Trial Version

2. What operating system are you using? (please also specify language)
Example: Windows 7 English

3. Which browser(s) are you using? (include version numbers)
Firefox 47.0.1
Thank you !
Yep but no need to kind of spam the Forum by opening several Threads about the exact same Qt with different Accounts. If @COSMOS is some Colleague of yours asking their own Qt, you are kind of screwing it for them as Duplicate Threads is a Show-stopper for me for answering Threads...
(You can still (ask to) delete the other Thread as long as nobody replies in it..., or you'll have to wait until the Forum Admin comes to the Forum to delete it as I was too quick to approve it and I cannot delete it anymore...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
peppe1
Posts: 11
Joined: Fri Mar 04, 2016 7:32 pm

Re: IMacros + XPATH:Count children of tag

Post by peppe1 » Wed Aug 03, 2016 1:05 pm

Sorry about this guys !
Yes he is my colleague and he thought that his post didn't go through..
I asked him to delete his post and will leave this one up.
Thank you and sorry again for the mixup.
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: IMacros + XPATH:Count children of tag

Post by iimfun » Wed Aug 03, 2016 1:12 pm

I doubt if you can do it with XPATH. Nevertheless if you use iMacros for Firefox and JavaScript Scripting Interface, try this code

Code: Select all

var numberOfRows = window.document.querySelectorAll("table.tableProduct tr").length;
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: IMacros + XPATH:Count children of tag

Post by chivracq » Wed Aug 03, 2016 1:31 pm

peppe1 wrote:Sorry about this guys !
Yes he is my colleague and he thought that his post didn't go through..
I asked him to delete his post and will leave this one up.
Thank you and sorry again for the mixup.
Yep, good, I saw that... (New-comers to the Forum and First-time Posters need to get their First Post(s)/Thread(s) approved manually by a Mod/Admin to prevent Spam and Duplicates...)

I don't know anything about XPATH/REGEX and/as I don't use it but I use a as well a different Technique like I have demonstrated in this Thread to count the Nb of Options in a DDLB.

In a Nutshell, the "aim of the game" is to do an 'EXTRACT=HTM' on your 'TBODY' Element and using 'EVAL()' + 'split('<tr>')' which returns an Array, the 'length' Property of that Array (-1) gives you the Result you are after...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply