Extracting text with asterisk

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
timlonggr
Posts: 2
Joined: Fri Jan 29, 2021 8:12 pm

Extracting text with asterisk

Post by timlonggr » Fri Jan 29, 2021 8:23 pm

1. What version of iMacros are you using?
iMacros for Firefox
VERSION BUILD=10021450

2. What operating system are you using? (please also specify language)
Windows 10, English

3. Which browser(s) are you using? (include version numbers)
Firefox 85.0

I'm trying to locate text on the page that includes a literal asterisk using the TAG command. I've tried several different methods for escaping it, but can't find anything that works. Any advice?

The most relevant post I could find was this viewtopic.php?f=7&t=9779&p=29270&hilit=asterisk#p29270 but it's nearly 11 years old and I'm hoping the answer is different now.

My goal on this page is to find these entries, click an edit button, remove the asterisk, and save the change.
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting text with asterisk

Post by chivracq » Fri Jan 29, 2021 9:05 pm

timlonggr wrote:
Fri Jan 29, 2021 8:23 pm

Code: Select all

1. What version of iMacros are you using?
iMacros for Firefox
VERSION BUILD=10021450

2. What operating system are you using? (please also specify language)
Windows 10, English

3. Which browser(s) are you using? (include version numbers)
Firefox 85.0
I'm trying to locate text on the page that includes a literal asterisk using the TAG command. I've tried several different methods for escaping it, but can't find anything that works. Any advice?

The most relevant post I could find was this viewtopic.php?f=7&t=9779&p=29270&hilit=asterisk#p29270 but it's nearly 11 years old and I'm hoping the answer is different now.

My goal on this page is to find these entries, click an edit button, remove the asterisk, and save the change.

'Free'/'PE' is missing from your FCI...?
=> iMacros for FF v10.0.2, 'Free'/'PE'...?, FF v85.0, Win10_Eng.

>>>

You didn't post any Script but from your "I'm trying to locate text on the page that includes a literal asterisk using the TAG command", I reckon you'll be using the 'TXT' Param for your Search..., which is indeed the most "efficient" Method to search some Text/Elements containing that Text...

Then well, are you only searching for those Asterisk Chars, or do you also have some "real Text" together with the Asterisk, and that Text will not appear on the Page also without Asterisk...?
=> Then you could use that "Text" for your Search...

>

You also have a 'SEARCH' Command... :idea:
But hum..., I find that Command pretty "clumsy" and not easy to use, and I "think" it only returns the 1st Occurrence...

>

=> You might be better off "building" your own Search Functionality by extracting some Content at a "higher" ('DIV') Level in the CSS Hierarchy/Structure of the Page (that will contain your Elements) with 'EXTRACT=TXT' or 'EXTRACT=HTM' and using 'EVAL()' with the very powerful 'split()' JS Method (which should be "immune" to the Asterisk being a "Special Char", (well, I think...! :P )), to then identify "more Text Info" close to the Asterisk, or some other Attribute(s) (or to dynamically "calculate" the correct "POS=n") to then reuse to tag the Elements that you want to find... :idea:

It's a little bit "High Level" and some "Advanced Technique", but not very complicated to implement if you understand the Principle, ah-ah...! :twisted:
The same Technique can also be used to "deal" with Dynamic ID's for example..., and it's more or less the same Principle like I once demonstrated in the following Thread...: 8)
- Re: Number of Options in a Select tag

Hum, but read in this Thread my Comment about "deactivating '!EXTRACT_TEST_POPUP'" if you extract at some "Root" Level ('BODY' or 'HTML') but also on some "early" 'DIV' on a large Page... :!:

>

Hum..., and some other "Idea" would be to use the 'TAG' + 'XPATH' Mode, I reckon you'll be able to escape the Asterisk Char (if that's ueberhaupt needed..., I don't know, I don't use that Mode...) using 'REGEXP'... :idea:
- (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...
timlonggr
Posts: 2
Joined: Fri Jan 29, 2021 8:12 pm

Re: Extracting text with asterisk

Post by timlonggr » Fri Jan 29, 2021 9:28 pm

I am using the Free edition, sorry for the omission

Here's what I've tried so far to (1) find the text with the asterisk and (2) click the very next EDIT button

FRAME F=4
TAG POS=1 TYPE=TD ATTR=TXT:"Application-*"
TAG POS=R1 TYPE=BUTTON FORM=ID:DocFormM ATTR=TXT:Edit

The asterisk will always appear just after the text "Application-" so there is something else to look for in addition to that, but it also appears without the asterisk (especially once I make my corrections).

Regarding the SEARCH command, I wouldn't mind if it only returned the first occurrence, because I want to correct them all. So I might give that a go tomorrow. I'll let you know how it goes.
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting text with asterisk

Post by chivracq » Fri Jan 29, 2021 9:58 pm

timlonggr wrote:
Fri Jan 29, 2021 9:28 pm
I am using the Free edition, sorry for the omission

Here's what I've tried so far to (1) find the text with the asterisk and (2) click the very next EDIT button

Code: Select all

FRAME F=4
TAG POS=1 TYPE=TD ATTR=TXT:"Application-*"
TAG POS=R1 TYPE=BUTTON FORM=ID:DocFormM ATTR=TXT:Edit
The asterisk will always appear just after the text "Application-" so there is something else to look for in addition to that, but it also appears without the asterisk (especially once I make my corrections).

Regarding the SEARCH command, I wouldn't mind if it only returned the first occurrence, because I want to correct them all. So I might give that a go tomorrow. I'll let you know how it goes.

Alright, then some "easier" Solution in "this Case" as you are (already) using 'Relative Positioning', could be...:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0

FRAME F=4
SET !EXTRACT NULL
TAG POS={{!LOOP}} TYPE=TD ATTR=TXT:"Application-*" EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('*'); y=x.length; if(y>1){z=1;} else{z=0;}; z;")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>VAR1:<SP>_{{!VAR1}}_
PAUSE
TAG POS=R{{!VAR1}} TYPE=BUTTON FORM=ID:DocFormM ATTR=TXT:Edit
... And you loop your Script... And comment out of course the 'PROMPT' and the 'PAUSE' once you've tested that "it works"...

>>>

I tested myself using the following Script, and that seems to work...:

Code: Select all

SET !VAR1 "Application-*"
SET !VAR2 EVAL("var v1='{{!VAR1}}'; var x,y,z; x=v1.split('*'); y=x.length; if(y>1){z=1;} else{z=0;}; z;")
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
(Tested on iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)
- (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...
Post Reply