Help on TAG or SEARCH

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Help on TAG or SEARCH

Post by KeithMar » Thu Jan 21, 2016 9:07 pm

IMacros for Firefox: VERSION BUILD=8961227
Windows Vista
Firefox V28

I have just downloaded iMacros for Firefox and would be grateful for some help with my first Macro. It should be simple so please forgive me for not finding an answer in the Wiki or FAQ. I have a table of links to book reviews on a page, with the second column indicating the country. Next to the link is sometimes an image. I need to click the first link that has UK in the second column, and has no image against the title. The html is below. In reality its a much longer list. Here I would want to click on Book 3. Grateful for any help or pointers you can offer

Thanks
Keith

Code: Select all

<html><body><table><tr>

<td><img src"star.jpg"></img><a href ="book1.htm">Book 1</a>Text1</td>
<td>UK</td></tr><tr>

<td><a href ="book2.htm">Book 2</a>Text2</td>
<td>USA</td></tr><tr>

<td><a href ="book3.htm">Book 3</a>Text3</td>
<td>UK</td></tr>
</table></body></html>
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Fri Jan 22, 2016 3:06 am

KeithMar wrote:

Code: Select all

IMacros for Firefox: VERSION BUILD=8961227
Windows Vista
Firefox V28
I have just downloaded iMacros for Firefox and would be grateful for some help with my first Macro. It should be simple so please forgive me for not finding an answer in the Wiki or FAQ. I have a table of links to book reviews on a page, with the second column indicating the country. Next to the link is sometimes an image. I need to click the first link that has UK in the second column, and has no image against the title. The html is below. In reality its a much longer list. Here I would want to click on Book 3. Grateful for any help or pointers you can offer

Thanks
Keith

Code: Select all

<html><body><table><tr>

<td><img src"star.jpg"></img><a href ="book1.htm">Book 1</a>Text1</td>
<td>UK</td></tr><tr>

<td><a href ="book2.htm">Book 2</a>Text2</td>
<td>USA</td></tr><tr>

<td><a href ="book3.htm">Book 3</a>Text3</td>
<td>UK</td></tr>
</table></body></html>
Hum, lucky nobody posted after you in the 5-6 hours I was away on my evening of Music, but you should mention it (= post a mini-Reply) when you edit your OP after you've posted it and that I have approved it..., especially to add your FCI (because I don't react otherwise to a Thread without FCI until you bump it 49 times...), but still, reading your Requirements, it sounds complex from just reading your Code Source... Can't you share the URL...!? Or upload an HTML Saveas of your Page to your Thread if it's behind L&P, I'm not reconstructing some HTML Page from your Source Code Excerpt to experiment with it...?
- (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...
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Re: Help on TAG or SEARCH

Post by KeithMar » Fri Jan 22, 2016 10:03 am

Apologies, and thanks for the response. I realised my mistake with FCI (from reading one of your own posts) hence the edit. The Book site is an internal corporate site but I originally tried to solve the same issue at fundingcircle.co.uk. To see the graphics adjacent to links you would need an account. I have attached a zipped saved version. I am looking to click on any of the loan links that don't have a small graphic adjacent provided there is a particular value in the Risk column.

Thanks for any help you can offer
Keith
Attachments
Funding Circle.zip
(15.56 KiB) Downloaded 371 times
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Fri Jan 22, 2016 10:11 pm

KeithMar wrote:Apologies, and thanks for the response. I realised my mistake with FCI (from reading one of your own posts) hence the edit. The Book site is an internal corporate site but I originally tried to solve the same issue at fundingcircle.co.uk. To see the graphics adjacent to links you would need an account. I have attached a zipped saved version. I am looking to click on any of the loan links that don't have a small graphic adjacent provided there is a particular value in the Risk column.

Thanks for any help you can offer
Keith
OK, interesting Case, I normally don't write Scripts for other Users but I thought that you wouldn't really understand what I would mean with (Double) Relative Positioning and using 'EVAL()' to compute the POS Number, so here is what I made of it...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO
SET !TIMEOUT_STEP 0
'URL GOTO=file:///D:/TEMP/iMacros/Temp/Funding%20Circle/Funding%20Circle.html

'Risk Value we want to use: (Valid Values are: A / A+ / B / C)
SET Risk_Value "A+"

SET !LOOP 1

'1- Use a 'Risk_Value' Element as an Anchor for Relative Positioning:
'TAG POS=3 TYPE=TD ATTR=TXT:A+ // (Recorded)
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:{{Risk_Value}}
'>
'Extract the URL of the Link on the Left of the Risk Field:
SET !EXTRACT NULL
TAG POS=R-1 TYPE=A ATTR=TXT:* EXTRACT=HREF
SET URL_Left {{!EXTRACT}}
'>
'Check if there is any Partition Graphic on the Left of the Anchor:
'TAG POS=1 TYPE=IMG ATTR=SRC:https://d2ondqc76inyu3.cloudfront.net/images/partitions.png // (Recorded)
SET !EXTRACT NULL
TAG POS=R-1 TYPE=IMG ATTR=SRC:https://*.cloudfront.net/images/partitions.png EXTRACT=TXT
'>
'If there is no Partition Graphic at R-1, we know that the Link is Good:
SET Partition EVAL("var s='{{!EXTRACT}}'; var x; if(s=='#EANF#'){x='NO';} else {x='YES';}; x;")
'>
'Extract the URL of the Link (if any) on the Right of the Partition Graphic:
SET !EXTRACT NULL
TAG POS=R1 TYPE=A ATTR=TXT:* EXTRACT=HREF
SET URL_Right {{!EXTRACT}}
'>
'SET Good_Link EVAL("var p='{{Partition}}'; var x; if(p=='NO'){x=1;} else {x=999;}; x;")
SET Good_Link EVAL("var ul='{{URL_Left}}'; var ur='{{URL_Right}}'; var x; if(ul!=ur){x=1;} else {x=999;}; x;")
'>
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:{{Risk_Value}}
'TAG POS=1 TYPE=A ATTR=TXT:Property<SP>Development<SP>In<SP>Liss<SP>3 // (Recorded)
TAG POS=R-{{Good_Link}} TYPE=A ATTR=TXT:*

PROMPT URL_Left:<SP>{{URL_Left}}<BR>URL_Right:<SP>{{URL_Right}}<BR>Partition<SP>Graphic?:<SP>{{Partition}}<BR>Good_Link:<SP>{{Good_Link}}

'PAUSE
(Written and Tested on iMacros for FF v8.8.2, Pale Moon v24.6.2 (=FF31), Win7-x64.)

I only used the Small Icon for the Graphic, I saw later that there was as well a Hammer for Bidding Closed that I didn't integrate in the Script but I guess you should understand the Principle... Enjoy...!
- (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...
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Re: Help on TAG or SEARCH

Post by KeithMar » Sat Jan 23, 2016 1:42 am

Hi Chivracq

Thank you for spending so much time to work this out. I hadn't realised how difficult this extraction could be. I've studied your solution and with a little more time will understand it fully and make it work in practice. If I have any more problems I know where to ask!

Thanks so much
Keith
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Sat Jan 23, 2016 6:04 am

KeithMar wrote:Hi Chivracq

Thank you for spending so much time to work this out. I hadn't realised how difficult this extraction could be. I've studied your solution and with a little more time will understand it fully and make it work in practice. If I have any more problems I know where to ask!

Thanks so much
Keith
Yep, don't worry, I'm always glad to help (at least for People who are able to use the Forum a bit correctly...) and to share...! I wouldn't be spending most of my Free Time on the Forum otherwise... :oops:

Dare to follow-up and to ask if there is anything you don't understand, or even if you understood everything, I was a bit in a hurry in the End as I had to go out, so I didn't finish it as neatly as I wanted... (I wanted to add some Reporting Capability with saving all the URL's to some .CSV File, but I didn't have the time...)
And "Graphic on the Left" means that there was already a Graphic on the Page before one Link, not that the Graphic is exactly on the Left of the Link...
- (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...
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Re: Help on TAG or SEARCH

Post by KeithMar » Sat Jan 23, 2016 11:02 pm

The method you used is very ingenious, and your script taught me a lot of imacros tricks in a very short time. I think I understand everything, whether I could write it myself is another matter! Would an alternative approach be to check the IMG name at R-1. If its Partions.png or Auction-hammer.png then we have a bad link, if its the bigger image in the first column we have a good link?

There are two other issues that I will need to solve. Your comments would be welcome as they would probably save me a lot of time. There is a banner across the page about halfway down. Below this the loans are marked 'bidding closed'. I don't want to follow any links below this point. I would have used !ENDOFPAGE but this is not available for Firefox so I'll need another plan.

Second is how to handle the LOOP. I need to run the macro in a loop so we keep looking for a link to click. When we find one, follow and extract data. But we need to stop the looping if there are no links to even consider, and reset back to 1 once we have clicked a link.

Thanks again for your help - I can't believe how dedicated you are! Hope you enjoyed the Music night as a break from a computer screen

Cheers, Keith
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Sun Jan 24, 2016 3:53 am

KeithMar wrote:The method you used is very ingenious, and your script taught me a lot of imacros tricks in a very short time. I think I understand everything, whether I could write it myself is another matter! Would an alternative approach be to check the IMG name at R-1. If its Partions.png or Auction-hammer.png then we have a bad link, if its the bigger image in the first column we have a good link?

There are two other issues that I will need to solve. Your comments would be welcome as they would probably save me a lot of time. There is a banner across the page about halfway down. Below this the loans are marked 'bidding closed'. I don't want to follow any links below this point. I would have used !ENDOFPAGE but this is not available for Firefox so I'll need another plan.

Second is how to handle the LOOP. I need to run the macro in a loop so we keep looking for a link to click. When we find one, follow and extract data. But we need to stop the looping if there are no links to even consider, and reset back to 1 once we have clicked a link.

Thanks again for your help - I can't believe how dedicated you are! Hope you enjoyed the Music night as a break from a computer screen

Cheers, Keith
Oh...!, Thanks for the Compliments, "Ingenious" is maybe a big word, I rather use "Creative"...
I didn't want to use JavaScript in '.js' Scripts for Conditional Behaviour so I had/have to always be a bit "Creative" to achieve what I want in pure '.iim', you might find the following Thread interesting, I've explained a bit the Techniques that I use...:
- Decision Making using iMacros/Possible Workarounds

About your "alternative approach to check the IMG name at R-1", I actually started in this Direction first (you can notice that I defined a 'Partition' Variable that I don't use, I only left it for Debugging in the PROMPT, and I first defined 'Good_Link' differently...), then I changed my mind for the Final Solution I used with 'URL_Left' and 'URL_Right' that I thought would be more reliable.
There is a Risk that if for any reason a Row doesn't have an Avatar Image, R-1 might catch the Partition Graphic from the Row above.
And if the URL and/or Name of the Partition Graphic had changed, the 'EVAL()' Statement to extract just the Name is always a bit complex with 'split()' / 'match()' / 'lastIndexOf()' / 'subStr()' / 'subString()' and you would have probably needed some Help again to modify the Script while with the Solution I gave you, you just need to record tagging the Elements again and you can modify the Script more easily...

>>>

I've added some Check about the Banner by simply using Relative Positioning on the Banner while checking at the same time if there is still at least one more Row with the desired Risk to check at the next Loop, and abort the Macro otherwise. + some mini-Reporting displayed at the end in the Side-Panel...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO
SET !TIMEOUT_STEP 0
'URL GOTO=file:///D:/TEMP/iMacros/Temp/Funding%20Circle/Funding%20Circle.html

'Risk Value we want to use: (Valid Values are: A / A+ / B / C)
SET Risk_Value "A+"

SET !LOOP 1

'Use a 'Risk_Value' Element as an Anchor for Relative Positioning:
'TAG POS=3 TYPE=TD ATTR=TXT:A+ // (Recorded)
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:{{Risk_Value}}
'>
'Extract the URL of the Link on the Left of the Risk Field:
SET !EXTRACT NULL
TAG POS=R-1 TYPE=A ATTR=TXT:* EXTRACT=HREF
SET URL_Left {{!EXTRACT}}
'>
'Check if there is any Partition Graphic on the Left of the Anchor:
'TAG POS=1 TYPE=IMG ATTR=SRC:https://d2ondqc76inyu3.cloudfront.net/images/partitions.png // (Recorded)
SET !EXTRACT NULL
TAG POS=R-1 TYPE=IMG ATTR=SRC:https://*.cloudfront.net/images/partitions.png EXTRACT=TXT
'>
'If there is no Partition Graphic at R-1, we know that the Link is Good:
SET Partition EVAL("var s='{{!EXTRACT}}'; var x; if(s=='#EANF#'){x='NO';} else {x='YES';}; x;")
'>
'Extract the URL of the Link (if any) on the Right of the Partition Graphic:
SET !EXTRACT NULL
TAG POS=R1 TYPE=A ATTR=TXT:* EXTRACT=HREF
SET URL_Right {{!EXTRACT}}
'>
'SET Good_Link EVAL("var p='{{Partition}}'; var x; if(p=='NO'){x=1;} else {x=999;}; x;")
SET Good_Link EVAL("var ul='{{URL_Left}}'; var ur='{{URL_Right}}'; var x; if(ul!=ur){x=1;} else {x=999;}; x;")
'>
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:{{Risk_Value}}
'TAG POS=1 TYPE=A ATTR=TXT:Property<SP>Development<SP>In<SP>Liss<SP>3 // (Recorded)
TAG POS=R-{{Good_Link}} TYPE=A ATTR=TXT:*

'Checking we are still above the Middle Banner and there is at least one more Row with the desired Risk to check,
'abort the Macro otherwise...
'Banner:
'TAG POS=1 TYPE=IMG ATTR=SRC:https://d2ondqc76inyu3.cloudfront.net/images/loan-parts-banner.png // (Recorded)
'>
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:{{Risk_Value}}
TAG POS=R1 TYPE=TD ATTR=TXT:{{Risk_Value}}
SET !EXTRACT NULL
TAG POS=R1 TYPE=IMG ATTR=SRC:https://*.cloudfront.net/images/loan-parts-banner.png EXTRACT=TXT

PROMPT URL_Left:<SP>{{URL_Left}}<BR>URL_Right:<SP>{{URL_Right}}<BR>Partition<SP>Graphic?:<SP>{{Partition}}<BR>Good_Link:<SP>{{Good_Link}}

SET Summary <SP><SP>No<SP>Error...!<BR><BR>
ADD Summary "Last Row with Risk = "
ADD Summary {{Risk_Value}}.<BR>({{!LOOP}}<SP>Row(s)<SP>processed...)<BR><BR><BR><BR>
SET !ERRORIGNORE NO
SET Abort_Macro EVAL("var s='{{!EXTRACT}}'; if(s=='#EANF#'){MacroError('{{Summary}}');}")
SET !ERRORIGNORE YES

'PAUSE
(Written and Tested on iMacros for FF v8.8.2, Pale Moon v24.6.2 (=FF31), Win7-x64.)

>>>

And yep, I enjoyed the Music, I'm a DJ so it's rather for other People to like my Music, ah-ah...! 8)
- (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...
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Re: Help on TAG or SEARCH

Post by KeithMar » Sun Jan 24, 2016 10:16 am

Its working really well. The lesson from your finished version is how to force a loop to stop. The only remaining issue I can see is that there needs to be one valid link to be found. Risk E for example finds an invalid 'good-link'. I'll try to solve this to test my learning

Thanks again
Keith
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Sun Jan 24, 2016 12:01 pm

KeithMar wrote:Its working really well. The lesson from your finished version is how to force a loop to stop. The only remaining issue I can see is that there needs to be one valid link to be found. Risk E for example finds an invalid 'good-link'. I'll try to solve this to test my learning

Thanks again
Keith
Ah OK, I deliberately didn't check for Current Row (for the Banner) as I thought it would have been redundant as the Macro should have already stopped at the previous Loop as I checked at the same time for above the Banner and the existence of a next valid Row to check at the next Loop.

You already have the Code for the Current Row, you just need to remove the Line including Next Row and to copy that Block at the beginning of the Macro.
Other Approach is then only to check for Current Row and not for next Row and when the Macro stops at Loop=n, you know that n-1 Rows have been processed...
- (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...
KeithMar
Posts: 6
Joined: Thu Jan 21, 2016 8:53 pm

Re: Help on TAG or SEARCH

Post by KeithMar » Sun Jan 24, 2016 10:12 pm

Thank you for all your time and assistance. You are a hero, and I am a better trained user!

Cheers
Keith
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help on TAG or SEARCH

Post by chivracq » Sun Jan 24, 2016 11:21 pm

KeithMar wrote:Thank you for all your time and assistance. You are a hero, and I am a better trained user!

Cheers
Keith
You're welcome, glad I could help... :D
- (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