Help needed with Keyword Assertion

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
Noodle105
Posts: 1
Joined: Sat May 02, 2020 2:33 pm

Help needed with Keyword Assertion

Post by Noodle105 » Sat May 02, 2020 2:54 pm

VERSION BUILD=10022823
iMacros 10 Browser
Windows 10

First of all, apologies for my naivety in this subject. I'm still pretty new to all this.
Basically I'm looking to write a code that goes to a user on a website, and if it finds the words 'Status: Online' it saves the username to an online.txt file, and if the username is offline it saves it to a offline.txt file, and then moves on to the next username, which would be given by {{!COL2}}.
Now I understand that the macro is searching for Status: Online or Status: Offline, but then the extract command is mutually exclusive regardless of whether or not it finds the text on the page anyway.
Thus when I run the script, it saves the username to both the Online file, and the Offline file.
Here's what I have so far:

Code: Select all

SET !DATASOURCE filter.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
FILTER TYPE=IMAGES STATUS=ON

URL GOTO=www.test.com/user={{!COL1}}
 
SEARCH SOURCE=TXT:"Status: Online"
'TAG POS=9 is the location of the username
TAG POS=9 TYPE=FONT ATTR=* EXTRACT=TXT

SET !CLIPBOARD {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER="my filepath" FILE=Online.txt
SET !EXTRACT NULL

SEARCH SOURCE=TXT:"Status: Offline"
'TAG POS=9 is the location of the username
TAG POS=9 TYPE=FONT ATTR=* EXTRACT=TXT

SET !CLIPBOARD {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER="C:\\Users\\cooki\\Desktop\\Users Online" FILE=Offline.txt
SET !EXTRACT NULL
Any help to get me on the right path would be greatly appreciated. Thank you!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help needed with Keyword Assertion

Post by chivracq » Sat May 02, 2020 4:53 pm

Noodle105 wrote:
Sat May 02, 2020 2:54 pm

Code: Select all

VERSION BUILD=10022823
iMacros 10 Browser
Windows 10
First of all, apologies for my naivety in this subject. I'm still pretty new to all this.
Basically I'm looking to write a code that goes to a user on a website, and if it finds the words 'Status: Online' it saves the username to an online.txt file, and if the username is offline it saves it to a offline.txt file, and then moves on to the next username, which would be given by {{!COL2}}.
Now I understand that the macro is searching for Status: Online or Status: Offline, but then the extract command is mutually exclusive regardless of whether or not it finds the text on the page anyway.
Thus when I run the script, it saves the username to both the Online file, and the Offline file.
Here's what I have so far:

Code: Select all

SET !DATASOURCE filter.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
FILTER TYPE=IMAGES STATUS=ON

URL GOTO=www.test.com/user={{!COL1}}
 
SEARCH SOURCE=TXT:"Status: Online"
'TAG POS=9 is the location of the username
TAG POS=9 TYPE=FONT ATTR=* EXTRACT=TXT

SET !CLIPBOARD {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER="my filepath" FILE=Online.txt
SET !EXTRACT NULL

SEARCH SOURCE=TXT:"Status: Offline"
'TAG POS=9 is the location of the username
TAG POS=9 TYPE=FONT ATTR=* EXTRACT=TXT

SET !CLIPBOARD {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER="C:\\Users\\cooki\\Desktop\\Users Online" FILE=Offline.txt
SET !EXTRACT NULL
Any help to get me on the right path would be greatly appreciated. Thank you!

"Hep needed with" has no "real" Use in a Thread Title on a Tech Forum... :idea:

Your Thread will probably get moved to the 'Data Extraction' Sub-Forum... I still approved it because the overall Quality is OK, and the 'General' Sub-Forum is always "OK" if you are "unsure" about which Sub-Forum to choose to open your Thread, but mention in that case that you "hesitated" about which Sub-Forum to select, or I usually don't answer when Threads are open in a "wrong" Sub-Forum... :!:

Hum, iMB v10.0.2 is a bit of a "strange" Version to use for sbd who's "still pretty new to all this", as it is already 5 or 6 years old, and I guess you've probably downloaded some Pirated Version from some "obscure" Website, ah-ah...! :wink: (But don't "worry", the Forum is about (Advanced) Users helping Users, we don't "care" about Licensing and "pirated Versions", oops...! :P )

But hum, there are maybe some "better" or at least more recent Versions you could use..., and all legal/legit, without needing to use some 'Pirated" Version, ah-ah...!: :wink:
- Current Versions for FF and CR are respectively v10.0.2 for FF (+ FF[56-76+]) and v10.0.5 for CR (+ CR[60-81+]), which both come in a 'Free' + 'PE' (= "Personal Edition") Versions, but you would need the 'PE' Version in your Case (which is not Free), because of the 'SAVEAS' Functionality.
- Current Version for IE is v12.6, also with 'Free' + 'PE' Versions, but the 'SAVEAS' Command is supported in the 'Free' Version.
- Current Version for iMB is v12.6 also, but there is only a 'Trial' Version, it's not "Free"...
- Another 'Free' Version that supports 'SAVEAS' (and much more...!) is v8.9.7 for FF, that works until FF56 (recommended = FF v55.0.3) or in Browsers forked on FF that didn't adopt the 'WebExtensions' Architecture, like 'Pale Moon' (=> PM28) or 'Basilisk' (=> v2019/2020) for example... :idea:

>>>

Alright..., hum, interesting Term, this "Assertion", it surprisingly doesn't get used much on the Forum, 1st time I use it myself, I think... :o

For the Functionality that you want in your Script, you want only 1 'SAVEAS' Command indeed, or your Script will save twice some Data to both Files like you describe..., and you need to "compute" dynamically the Filename to which File you want to save, depending on if 'Status' = "Online" or "Offline" gets found. :idea:
For this you'll need the 'EVAL()' Command, to "analyze" the Result of both 'SEARCH' Commands, and to spit out "Online.txt" or "Offline.txt" to reuse for the 'SAVEAS'. :idea:

>>>

And hum..., I never use the 'SEARCH' Command myself..., as I don't "like it", and there are easier and more "powerful" Techniques to get the same "Result" and much more "Applied Functionality"...: It might be easier to "directly" try to tag both "Status: On/Offline" Elements (+ 'EXTRACT=TXT' maybe), + extracting your 'Username' using 'Relative Positioning'... :idea:

It can probably also be done with just 1 'TAG'/'EXTRACT' Statement on "Status:<SP>O*line" + extracting the 'Username', with or without 'Relative Positioning', the "O*line" will already return "Online" or "Offline" that you can directly reuse for the Filename, you don't even need any 'if'/'else' Condition(s)... That would be the most straightforward Implementation, I would think... :idea:
- (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