XPATH QUERY

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

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.

XPATH QUERY

by footyfacts on Sat Aug 26, 2017 9:00 pm

Firefox 52.2.1 (32-bit)
Imacros VERSION BUILD=9030808
Windows XPsp2

They changed the page on me and XPATH is a bit obtuse for an old man like me
I now get the product code and product price extract twice

My code (courtesy of others who have helped previously)

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]" Extract=Txt <== This ends up with 553919553919
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]" Extract=Txt <== this ends up with $98.60$98.60
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt
SAVEAS TYPE=EXTRACT FOLDER=F:\PC-Stuff\Sendmail\DanPages FILE=ALM_EXT.CSV


SAMPLE TR DATA

<tr bgcolor='#ECECFF'>
<td><a href="javascript:launchWindow('History?ProductId=553919');" title="CRWN SEAL 750ML" class="phtip">553919</a> <input type="hidden"
name="ProductId" value="553919"/></td>

<td>CRWN SEAL MOSC 750ML</td>

<td align="center">6</td>

<td align="center">6</td>

<td align="right">$ 98.60<input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>

<td align="center"><a title="No Current Allowance" class="alwtip">$ 0</a></td>

<td align="center"><font face="courier new" size="3"><tt><b>&nbsp;</b></tt></font><input type="text" name="OrderCtnQty" value=""
class="formfield" onfocus="resetKeepAliveTime();" maxlength="3" size="5"/></td>

<td align="center"><input type="hidden" name="OrderUnitQty" value=""/>&nbsp;</td>

<td><a href="javascript:launchWindow('/alm/user/LineCalculator?ProductId=553919&PackQty=6&WetRate=29.0&
BaseCostPriceExGST=69.49','popup',600,400);" title="View Line Calculator" class="tip"><img src="media/images/icons/inner_calculator.gif"
align="absmiddle" border="0" hspace="1" null></a> <input type="hidden" name="UnitPriceExGST" value="98.60"/></td>

<td align="center"><INPUT type="hidden" name="IsAddProduct" value="false"><input type="checkbox" name="IsAddProduct"/></td>

</tr>
footyfacts
 
Posts: 8
Joined: Tue Jul 02, 2013 4:48 am

Re: XPATH QUERY

by iimfun on Sun Aug 27, 2017 11:32 pm

Maybe the input elements cause troubles. What about this way?
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
or
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/input" Extract=Txt

and
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/input" Extract=Txt

If it doesn't work then you should use the EVAL command.
iimfun
 
Posts: 239
Joined: Tue Jul 19, 2016 6:06 am

Re: XPATH QUERY

by footyfacts on Sat Sep 02, 2017 3:55 am

Thanks

both /a or /input work for the first cell however in the interim they changed the page slightly
and the 5th element now contains a <nobr>

However whilst the following works when these is no BOLD element it does not work when there is a BOLD
(The BOLD is only present when a product is onl special, the NOBR is always present)

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr" Extract=Txt


<td align="right"><b><nobr>&nbsp;$ 53.37&nbsp;</nobr></b><input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>

<td align="right"><nobr>&nbsp;$ 53.37&nbsp;</nobr><input type="hidden" name="UniversalDealIncGST" value="0.00" /> </td>

GregF
footyfacts
 
Posts: 8
Joined: Tue Jul 02, 2013 4:48 am

Re: XPATH QUERY

by footyfacts on Sat Sep 02, 2017 4:58 pm

My solution isn't elegant however the following does solve my problem
although it is probably going to break when they change things on me again
I do have the "safety" in knowing that change is not often because it is
not an e-commerce site it is just the wholesaler/retailer ordering

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
set !LOOP 1
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/b[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt

I would still like to know however why the NOBR fails when there is a <b><nobr> tag pair
surely the test is irrelevant to the precedence of the tags and indeed why the original
extracts the $$ amount twice (I know why the 1st tag did as it is there twice)

gregF
footyfacts
 
Posts: 8
Joined: Tue Jul 02, 2013 4:48 am

Re: XPATH QUERY

by chivracq on Sat Sep 02, 2017 7:32 pm

Quoting all Posts in this Thread to be able to follow it a bit as it sounds a bit interesting, from @iimfun's Reply, but I guess it's not directly solved from the several Replies from @OP, that seems to belong to the in total 3 Users I've foed since I joined the Forum about 4 years ago (and started to help other Users...), but anyway I quote all Posts because I don't see them otherwise...

And hum, @OP mentioning their FCI directly (is nearly too perfect...!) , I guess my "pain-in-the-ass/foe" Thing probably comes from me asking @OP to mention their FCI at some time, and I guess it went awrok..., oops...!

footyfacts wrote:
Code: Select all
Firefox  52.2.1 (32-bit)
Imacros VERSION BUILD=9030808
Windows XPsp2


They changed the page on me and XPATH is a bit obtuse for an old man like me
I now get the product code and product price extract twice

My code (courtesy of others who have helped previously)

Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]" Extract=Txt                 <== This ends up with  553919553919
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]" Extract=Txt                  <== this ends up with $98.60$98.60
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt
SAVEAS TYPE=EXTRACT FOLDER=F:\PC-Stuff\Sendmail\DanPages FILE=ALM_EXT.CSV


SAMPLE TR DATA
Code: Select all
<tr bgcolor='#ECECFF'>
  <td><a href="javascript:launchWindow('History?ProductId=553919');"  title="CRWN SEAL 750ML" class="phtip">553919</a> <input type="hidden"
                    name="ProductId" value="553919"/></td>
  <td>CRWN SEAL MOSC 750ML</td>
  <td align="center">6</td>
  <td align="center">6</td>
  <td align="right">$ 98.60<input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>
  <td align="center"><a   title="No Current Allowance" class="alwtip">$ 0</a></td>
  <td align="center"><font face="courier new" size="3"><tt><b> </b></tt></font><input type="text" name="OrderCtnQty" value=""
        class="formfield" onfocus="resetKeepAliveTime();" maxlength="3" size="5"/></td>
  <td align="center"><input type="hidden" name="OrderUnitQty" value=""/> </td>
   <td><a href="javascript:launchWindow('/alm/user/LineCalculator?ProductId=553919&PackQty=6&WetRate=29.0&
          BaseCostPriceExGST=69.49','popup',600,400);"  title="View Line Calculator" class="tip"><img src="media/images/icons/inner_calculator.gif"
          align="absmiddle" border="0" hspace="1" null></a>                  <input type="hidden" name="UnitPriceExGST" value="98.60"/></td>
   <td align="center"><INPUT type="hidden" name="IsAddProduct" value="false"><input type="checkbox" name="IsAddProduct"/></td>
</tr>

iimfun wrote:Maybe the input elements cause troubles. What about this way?
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
or
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/input" Extract=Txt

and
Code: Select all
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/input" Extract=Txt

If it doesn't work then you should use the EVAL command.

footyfacts wrote:My solution isn't elegant however the following does solve my problem
although it is probably going to break when they change things on me again
I do have the "safety" in knowing that change is not often because it is
not an e-commerce site it is just the wholesaler/retailer ordering

Code: Select all
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
set !LOOP 1
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/b[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt


I would still like to know however why the NOBR fails when there is a <b><nobr> tag pair
surely the test is irrelevant to the precedence of the tags and indeed why the original
extracts the $$ amount twice (I know why the 1st tag did as it is there twice)

gregF

Arrgghh, but nope...,!, I thought it was the perfect try-and-fall/fail Thread to learn 'XPATH', but nope...!: URL not mentioned..., pity...!! :roll:
But it looks a bit like the 'EVENT' Mode and if selecting/locating Cells in an HTML Table, Relative Positioning would do the same job and is much easier to use, I would think... :?

Maybe one day @OP will find the ']CODE[' Meta-Tags...!? :wink:
- (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: 6485
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: XPATH QUERY

by footyfacts on Sun Sep 03, 2017 8:19 pm

Pesky MetaTags '[code][/code]'

URL was not useful to problem and not posted as you have to login to the secure site
which is why I posted HTML snippets of data

Personally I think the final Code snippets for XPath are now quite useful for a Tyro
and could set many a beginner on their way

I am too cranky nowadays to bother having another comp language/markup in my brain
beyond the 200/300 in there now after 38 years of coding

GregF
footyfacts
 
Posts: 8
Joined: Tue Jul 02, 2013 4:48 am


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 10 guests

-->