xpath extract multiple answer

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
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
DDon
Posts: 20
Joined: Sat Aug 06, 2016 1:41 pm

xpath extract multiple answer

Post by DDon » Sat Aug 06, 2016 1:50 pm

Hi,


I'm using Firefox 48 with imacro VERSION BUILD=8970419

Windows 10

I'm trying to extract the element in the XML file. However, the xpath have multiple result. Is there anyway that we can extract all the result match with the xpath and save each element in each variable?

I got the code TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy" EXTRACT=TXT and get the error

RuntimeError: ambiguous XPath expression: /Prefilling2016/PrivateHealthInsurance/PHIPolicies/PHIPolicy, line 3 (Error code: -982)

Tried to google but still can't find the solution. Thank you.
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: xpath extract multiple answer

Post by chivracq » Sat Aug 06, 2016 6:06 pm

DDon wrote:Hi,


I'm using

Code: Select all

Firefox 48 with imacro VERSION BUILD=8970419
Windows 10
I'm trying to extract the element in the XML file. However, the xpath have multiple result. Is there anyway that we can extract all the result match with the xpath and save each element in each variable?

I got the code

Code: Select all

TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy" EXTRACT=TXT
and get the error
RuntimeError: ambiguous XPath expression: /Prefilling2016/PrivateHealthInsurance/PHIPolicies/PHIPolicy, line 3 (Error code: -982)
Tried to google but still can't find the solution. Thank you.
There is probably a way using "Standard" TAG Mode with 'POS=1' / 'POS=2' etc...

You have the 'SEARCH' Command as well.

I don't use 'XPATH' nor 'SEARCH' but you can "mimic" those Commands by first extracting some higher HTML Element containing all your Elements that you want to extract and then use 'EVAL()' + 'split()' to isolate the Data that you want to keep...

Post the URL of your Page or upload your XML File to the Thread (zipped, Max 256Kb) if you don't come up by yourself...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: xpath extract multiple answer

Post by iimfun » Tue Aug 09, 2016 6:25 am

If the number of multiple elements is known a priori, just specify them directly

Code: Select all

TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy[1]" EXTRACT=TXT
TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy[2]" EXTRACT=TXT
...
DDon
Posts: 20
Joined: Sat Aug 06, 2016 1:41 pm

Re: xpath extract multiple answer

Post by DDon » Thu Aug 11, 2016 11:59 am

Thank you your post, this help a lot and I can extract what I want now.

I haven't learned any programing language so I can never fully understand the val function of the iMacro,

1. How can I eval the extract text from 1963-11-09 to 09/11/1963?

2. Is there any solution that we save fully page to .aspx but not html? I found no solution after google a few days :(

I appreciate everyone support in the forums. Thank you.
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: xpath extract multiple answer

Post by iimfun » Thu Aug 11, 2016 2:23 pm

1. How can I eval the extract text from 1963-11-09 to 09/11/1963?
Here is a code for that

Code: Select all

SET !EXTRACT EVAL("'{{!EXTRACT}}'.split('-').reverse().join('/');")
Post Reply