iMacros Script to Extract Specific Text From Static Position

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
iMacrosScripter
Posts: 8
Joined: Thu Apr 27, 2017 3:10 pm

iMacros Script to Extract Specific Text From Static Position

Post by iMacrosScripter » Tue Feb 27, 2018 10:11 pm

Problem Description Information:
1. iMacros Version: iMacros for Firefox 8.9.7 (VERSION BUILD=8970419)
2. Windows 10 (64-bit) [English]
3. Firefox 45.9.0
4. Included demos work ok.
5. Included VBS sample scripts run ok.
6. Not applicable/no specific recording or replay fails on a specific website.
7. Not applicable/no test for encounter of the same problem with the: iMacros Browser, iMacros for Internet Explorer, iMacros for Firefox, and iMacros for Chrome.

Problem:
I am trying to write an iMacros script that checks a webpage, and in that webpage checks a specific webpage position for a specific text that is positioned always to the right of a naming text that always has the same position on that webpage (naming text is: "Location:") where the value of this specific text to the right of that naming text can change between 1 to 26 different values (say: A-Z), Once iMacros "reads" this specific text, then have iMacros take that specific text and look it up in a specific Excel file where that specific text has specific values (say: A to Z) located in column A and then have iMacros return the corresponding output value from column B (say: 101-126) on the same row.
How would I script this in iMacros?

So far, using the iMacros built in recorder I have made the following progress in iMacros (webpage image with iMacros recorder "blue boxes" listed below):
Script:

Code: Select all

VERSION BUILD=8970419 RECORDER=FX
TAB T=1
URL GOTO=https://URL.aspx
TAG POS=1 TYPE=DIV ATTR=ID:SectionHeader
TAG POS=1 TYPE=SPAN ATTR=ID:tip_0
FRAME F=2
TAG POS=1 TYPE=A ATTR=TXT:Communication2
WAIT SECONDS=1
TAG POS=1 TYPE=TD ATTR=TXT:Location:
WAIT SECONDS=1
TAG POS=1 TYPE=TD ATTR=TXT:SPECIFIC-TEXT
WAIT SECONDS=1
I have pasted below an image of the webpage I am trying to script for; where it needs to read the "specific text" located to the right of the text "Location:" where that text is always in the same position on the webpage and always to the right of "Location:" - how would I script this in iMacros?
Webpage Image:
Image
TEST-R4(JPEG).jpg
EDIT1: Thanks Chivracq, changes made.

EDIT2: Chivracq, thanks for posting in my PM thread. I wanted to PM you to ask you to update your reply on my previous thread, so as to edit your reply in that previous thread to requote my updated edited original post as there was some extraneous information that I needed to edit out that should have been edited out when I first posted that thread, so I updated that previous thread. If you would be able to edit your original reply to requote my updated edited original post; I can then post my solution to that thread, so others can benefit. I am thankful to you for helping me solve that issue in that thread. Thanks for all the help!
Last edited by iMacrosScripter on Thu Mar 01, 2018 4:28 pm, edited 13 times in total.
chivracq
Posts: 8136
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Script to Extract Specific Text From Static Posi

Post by chivracq » Tue Feb 27, 2018 11:26 pm

iMacroScripter wrote:Problem Description Information:
1. iMacros Version: iMacros for Firefox 8.9.7 (VERSION BUILD=8970419)
2. Windows 10 (64-bit) [English]
3. Firefox 45.9.0
4. Included demos work ok.
5. Included VBS sample scripts run ok.
6. Not applicable/no specific recording or replay fails on a specific website.
7. Not applicable/no test for encounter of the same problem with the: iMacros Browser, iMacros for Internet Explorer, iMacros for Firefox, and iMacros for Chrome.

I am trying to write an iMacros script that checks a webpage, and in that webpage checks a specific webpage position for a specific text that is positioned always to the right of a naming text that always has the same position on that webpage (naming text is: "Location:") where the value of this specific text to the right of that naming text can change between 1 to 26 different values (say: A-Z), Once iMacros "reads" this specific text, then have iMacros take that specific text and look it up in a specific Excel file where that specific text has specific values (say: A to Z) located in column A and then have iMacros return the corresponding output value from column B (say: 101-126) on the same row.
How would I script this in iMacros?

So far, using the iMacros built in recorder I have made the following progress in iMacros (webpage image with iMacros recorder "blue boxes" listed below):
Script:

Code: Select all

VERSION BUILD=8970419 RECORDER=FX
TAB T=1
URL GOTO=https://URL.aspx
TAG POS=1 TYPE=DIV ATTR=ID:SectionHeader
TAG POS=1 TYPE=SPAN ATTR=ID:tip_0
FRAME F=2
TAG POS=1 TYPE=A ATTR=TXT:Communication2
WAIT SECONDS=1
TAG POS=1 TYPE=TD ATTR=TXT:Location:
WAIT SECONDS=1
TAG POS=1 TYPE=TD ATTR=TXT:SPECIFIC-TEXT
WAIT SECONDS=1
I have pasted below an image of the webpage I am trying to script for; where it needs to read the "specific text" located to the right of the text "Location:" where that text is always in the same position on the webpage and always to the right of "Location:" - how would I script this in iMacros?
Webpage Image:
Image
TEST-_R4_JPEG.jpg
Mini-Compliment for the "good Quality" of your OP, this is (unfortunately) quite rare on the Forum... :wink:
... Except that you could use the ]CODE[ Meta-Tags for your Script, and I couldn't load your Image, you can better upload it directly to your Thread rather than locate it on some external Server, I'm re-uploading it to your Thread... :idea:

:arrow: But-but-but, hum-hum..., sorry, big "Show-stopper" for me to want to help you again, but you never followed up on your previous Thread...! Nice to ask for Help on the Forum but if you don't follow up on your Threads, then it's a bit useless I would think...! :roll:

=> First follow up on your previous Thread and finish it "correctly" by sharing your Solution/final Script to make it useful for other Users as well, and you can maybe bump this one in about 10 months if you are still looking for a Solution then... :idea:
OK, make it 5 months, I'll be "nice"...! :wink:

OK, I might be "even nicer" after you'll have handled your previous Thread "correctly", this one is a bit "Interesting", ah-ah...! :oops:
But if you search the Forum a bit, I've already posted/explained several Solutions about your Scenario several times in different Threads, I can find 4-5-6 different Solutions in a few seconds..., most in pure '.iim' that you can easily convert to '.js' or '.vbs'... :idea:
- (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...
iMacrosScripter
Posts: 8
Joined: Thu Apr 27, 2017 3:10 pm

Re: iMacros Script to Extract Specific Text From Static Posi

Post by iMacrosScripter » Thu Mar 01, 2018 3:47 pm

chivracq wrote: Mini-Compliment for the "good Quality" of your OP, this is (unfortunately) quite rare on the Forum... :wink:
... Except that you could use the ]CODE[ Meta-Tags for your Script, and I couldn't load your Image, you can better upload it directly to your Thread rather than locate it on some external Server, I'm re-uploading it to your Thread... :idea:
Changes made, thanks.
chivracq wrote: => First follow up on your previous Thread and finish it "correctly" by sharing your Solution/final Script to make it useful for other Users as well, and you can maybe bump this one in about 10 months if you are still looking for a Solution then... :idea:
OK, make it 5 months, I'll be "nice"...! :wink:
I finished my previous thread "correctly" by sharing my solution/final script to make it useful for other users; I am still looking for some help on this current issue.
chivracq wrote: OK, I might be "even nicer" after you'll have handled your previous Thread "correctly", this one is a bit "Interesting", ah-ah...! :oops:
But if you search the Forum a bit, I've already posted/explained several Solutions about your Scenario several times in different Threads, I can find 4-5-6 different Solutions in a few seconds..., most in pure '.iim' that you can easily convert to '.js' or '.vbs'... :idea:
This is very interesting as I am looking for a solution in pure ".iim". I have made some progress since last post, and can now extract the needed data to .CSV file the script progress is listed below.

I am still stuck though on how to get iMacros to take the extraction in the test.csv file, and have iMacros look it up to match that data extraction in another column (say: A-Z), and give the needed output (say: 101-126)? How would I do this?
Script

Code: Select all

VERSION BUILD=8970419 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=*URL*.aspx
TAG POS=1 TYPE=SPAN ATTR=ID:tip_0
FRAME NAME="*FrameTickets*"
TAG POS=1 TYPE=TD ATTR=TXT:First<SP>Ticket<SP>A*
FRAME F=2
TAG POS=1 TYPE=A ATTR=TXT:Communication2

TAG POS=1 TYPE=TD ATTR=TXT:Location:
WAIT SECONDS=1
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Directory\ FILE=test.csv
chivracq
Posts: 8136
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Script to Extract Specific Text From Static Posi

Post by chivracq » Thu Mar 01, 2018 7:52 pm

iMacroScripter wrote:
chivracq wrote: Mini-Compliment for the "good Quality" of your OP, this is (unfortunately) quite rare on the Forum... :wink:
... Except that you could use the ]CODE[ Meta-Tags for your Script, and I couldn't load your Image, you can better upload it directly to your Thread rather than locate it on some external Server, I'm re-uploading it to your Thread... :idea:
Changes made, thanks.
chivracq wrote: => First follow up on your previous Thread and finish it "correctly" by sharing your Solution/final Script to make it useful for other Users as well, and you can maybe bump this one in about 10 months if you are still looking for a Solution then... :idea:
OK, make it 5 months, I'll be "nice"...! :wink:
I finished my previous thread "correctly" by sharing my solution/final script to make it useful for other users; I am still looking for some help on this current issue.
chivracq wrote: OK, I might be "even nicer" after you'll have handled your previous Thread "correctly", this one is a bit "Interesting", ah-ah...! :oops:
But if you search the Forum a bit, I've already posted/explained several Solutions about your Scenario several times in different Threads, I can find 4-5-6 different Solutions in a few seconds..., most in pure '.iim' that you can easily convert to '.js' or '.vbs'... :idea:
This is very interesting as I am looking for a solution in pure ".iim". I have made some progress since last post, and can now extract the needed data to .CSV file the script progress is listed below.

I am still stuck though on how to get iMacros to take the extraction in the test.csv file, and have iMacros look it up to match that data extraction in another column (say: A-Z), and give the needed output (say: 101-126)? How would I do this?
Script

Code: Select all

VERSION BUILD=8970419 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=*URL*.aspx
TAG POS=1 TYPE=SPAN ATTR=ID:tip_0
FRAME NAME="*FrameTickets*"
TAG POS=1 TYPE=TD ATTR=TXT:First<SP>Ticket<SP>A*
FRAME F=2
TAG POS=1 TYPE=A ATTR=TXT:Communication2

TAG POS=1 TYPE=TD ATTR=TXT:Location:
WAIT SECONDS=1
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Directory\ FILE=test.csv
OK, I quote your previous Reply "in bulk", together with my own Quotes..., ah-ah...!

But OK, good-good, you've already found the best Solution indeed for extracting your Text Field next to the 'Location' Field by using Relative Positioning. Perfect... That was the "easiest" part...! 8)
(And that Functionality is btw completely documented in the Wiki..., well..., except for "certain" cases where you need to use "Double Relative Positioning" which is not documented, but I have explained the Principle in several Threads already, if you are interested... (But you didn't need it for this one...)) :idea:

Now about the 2nd part of your Scenario, about locating a specific '[1-26]/[A-Z]' Cell in Col_1 in your '.CSV' and its corresponding '[101-126]' Value in Col_2, that's a little bit more "complicated"..., but not too much, ah-ah...!, and there are several ways to implement that Functionality. :D

Well, you mention that "5. Included VBS sample scripts run ok." meaning you must be using or can use the Scripting Interface... (You don't mention which Version btw...?) If you can use a '.vbs' Script, then you could handle that part directly from the '.vbs' Script, you then have Full Control on Excel. I've seen Solutions for that, either on our Forum and/or maybe on SOF (Stackoverflow Forum) in the 'Excel'/'.vbs'/'.vba' Threads.

But it can be done in pure '.iim' as well, with a few Techniques that I have explained in several Threads already:
- Re: Select file from folder which is not already in CSV file
Very recent Thread, pity (for you...!) that User never bothered to follow up (hum..., sounds familiar...!? :wink: ), you would have your Script already as you both want the same Functionality actually.
Check the Thread I linked to in my Post about the last Row in a '.CSV' as I give a lot of Info (and a Script) in that Thread...

Another related Thread:
- Re: Setting a Variable Column Number to use with a Data Sour[ce]
The same Technique can be used in your Case, and the "one more" Link leads to a Post/Thread by TechSup for the latest iMacros for CR v10 Free which doesn't support FIO anymore (File Access) and how you can use an HTML Table as a DataSource, a Technique I've been using (and "advertizing" as well in some Cases on the Forum) for several years already...

And there was about 1 or 2 years ago some Thread I remember where I think the User wanted more or less the same Functionality like you want, it was about "Route+Cities" as Keywords, I'll see if I can locate that Thread, I don't remember if they had posted their final Script...
'>
=> Yep, found it directly...!, was indeed the only Thread on the Forum with "Route+Cities" as Keywords (+ this current one as well now, of course), hum, was "only" from 6 months ago and not 1 or 2 years like I thought, ah-ah...!, that was a "perfect" Thread, with an "exemplary" User, just a few "Instructions" and they managed to write their Script, that they nicely shared...: :D
- IF THEN ELSE to input varying Data from .CSV list

And hum-hum-hum...!, there is probably some even simpler Solution in your Case I think, as all Threads I've referred you to until now are for Scenarios where you don't know in advance where your Data is located in your '.CSV' (and if it is even present at all...!). But I guess your '.CSV' will only contain 26 Rows (or 27 if you have a Header in it), meaning your '[1-26]' will already correspond exactly to the correct '!DATASOURCE_LINE' (or +1 if you have a Header). If that's the case, that would be the easiest Scenario/Solution...! Pretty straightforward then... 8)
Last edited by chivracq on Tue Mar 06, 2018 6:47 pm, edited 2 times in total.
- (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: 8136
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Script to Extract Specific Text From Static Posi

Post by chivracq » Tue Mar 06, 2018 6:44 pm

Hum, 1 week now after you've opened this Thread and 5 days after I posted a long Reply mentioning/explaining several Solutions, I was "hoping" for some Follow-up, especially after I had already "complained" about the [lack of/very poor] Follow-up on your first Thread, but nope..., nothing at all... Not really impressed, to be honest... :shock:
I answered your Thread about Excel as well, one day later I think, no Follow-up either... I guess that was probably the last time I was trying to help you, I think... Good luck with your Script(s) and with other (Advanced) Users if you need further Help... 8)
- (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...
Post Reply