IMacros + XPATH:Count children of tag

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

IMacros + XPATH:Count children of tag

by peppe1 on Wed Aug 03, 2016 2: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 !
peppe1
 
Posts: 11
Joined: Fri Mar 04, 2016 12:32 pm

Re: IMacros + XPATH:Count children of tag

by chivracq on Wed Aug 03, 2016 3: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6487
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: IMacros + XPATH:Count children of tag

by peppe1 on Wed Aug 03, 2016 6:05 am

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.
peppe1
 
Posts: 11
Joined: Fri Mar 04, 2016 12:32 pm

Re: IMacros + XPATH:Count children of tag

by iimfun on Wed Aug 03, 2016 6:12 am

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;
iimfun
 
Posts: 239
Joined: Tue Jul 19, 2016 6:06 am

Re: IMacros + XPATH:Count children of tag

by chivracq on Wed Aug 03, 2016 6:31 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6487
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 4 guests

-->