Script to remove excess white spaces not working

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Loxigan
Posts: 7
Joined: Wed Nov 09, 2016 5:37 pm

Script to remove excess white spaces not working

Post by Loxigan » Sun Nov 13, 2016 6:05 am

Using imacros Firefox ad-on version 8.9.7 ~ using older version because newest version does not support the imns namespace and also some other features I need.

After doing some research, I implemented the following script to remove excess white spaces from the data extraction, but I am getting an unusual result as show below. How can I do it correctly so that those pesky white spaces are removed?

Thanks!

Here is how the address looks on the webpage (with hypothetical values):

Code: Select all

5555 S Pickles Ave.
Ste 2000
Somecity, Somestate 55555

Code: Select all

TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
SET address EVAL("var extract = \"{{!EXTRACT}}\"; extract.replace(\"#EANF#\", \"\").replace(\"NODATA\", \"\").replace(/^\\s*|,\\s*$/g, \"\");")
SET !EXTRACT NULL
Output to csv file:

Code: Select all

"5555 S Pickles Ave.
						 
						
							Ste 2000
						
						 
						
							Somecity, 
						
						Somestate
						33333 
					"
chivracq
Posts: 9317
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Script to remove excess white spaces not working

Post by chivracq » Sun Nov 13, 2016 2:28 pm

Loxigan wrote:Using

Code: Select all

imacros Firefox ad-on version 8.9.7
~ using older version because newest version does not support the imns namespace and also some other features I need.

After doing some research, I implemented the following script to remove excess white spaces from the data extraction, but I am getting an unusual result as show below. How can I do it correctly so that those pesky white spaces are removed?

Thanks!

Here is how the address looks on the webpage (with hypothetical values):

Code: Select all

5555 S Pickles Ave.
Ste 2000
Somecity, Somestate 55555

Code: Select all

TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
SET address EVAL("var extract = \"{{!EXTRACT}}\"; extract.replace(\"#EANF#\", \"\").replace(\"NODATA\", \"\").replace(/^\\s*|,\\s*$/g, \"\");")
SET !EXTRACT NULL
Output to csv file:

Code: Select all

"5555 S Pickles Ave.
						 
						
							Ste 2000
						
						 
						
							Somecity, 
						
						Somestate
						33333 
					"
FCIM...! :mrgreen:
Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Versions/Browsers or get broken from some specific Version... (and I usually simply don't read when FCI is not mentioned...)
v8.9.7 is btw a completely "legit" Version to use, v9.0.3 is indeed pretty buggy and limited... :oops:
=> iMacros for FF v8.9.7, FF47/49...?, OS...?

But OK, I had a look at your Case with the Info you provided, even if I'm not very good with Global 'replace()' and I cannot reproduce your Pb...

Script I used to test:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1

'5555 S Pickles Ave.
'Ste 2000
'Somecity, Somestate 55555

SET Addr_1 "5555 S Pickles Ave."
SET Addr_2 "Ste 2000"
SET Addr_3 "Somecity, Somestate 55555"
SET Addr {{Addr_1}}<BR>{{Addr_2}}<BR>{{Addr_3}}

'TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
'SET address EVAL("var extract = \"{{!EXTRACT}}\"; extract.replace(\"#EANF#\", \"\").replace(\"NODATA\", \"\").replace(/^\\s*|,\\s*$/g, \"\");")
'SET !EXTRACT NULL
SET address EVAL("var extract = \"{{Addr}}\"; extract.replace(\"#EANF#\", \"\").replace(\"NODATA\", \"\").replace(/^\\s*|,\\s*$/g, \"\");")

PROMPT Addr:<BR>_{{Addr}}_<BR><BR>address:<BR>_{{address}}_
The Result of the PROMPT is then:
Addr:
_5555 S Pickles Ave.
Ste 2000
Somecity, Somestate 55555_

address:
_5555 S Pickles Ave.
Ste 2000
Somecity, Somestate 55555_
... which looks normal to me, or I guess what you expect...
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10-x64.)

What we actually need for "proper" Testing is the exact full Content of your 'EXTRACT=TXT', and provide as well the exact full Content of 'EXTRACT=HTM' on the same 'TD' Field...
And even better of course would be it you provided the URL to your Site/Page or uploaded some HTML Saveas of the Page (zipped, Max 256Kb) to your Thread if it's behind Login&Password... :roll:
- (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...
Loxigan
Posts: 7
Joined: Wed Nov 09, 2016 5:37 pm

Re: Script to remove excess white spaces not working

Post by Loxigan » Sun Nov 13, 2016 9:44 pm

Hi,

Thanks for the quick reply.

Imacros version - 8.9.7
FF Version - 49.0.2
OS - Windows 10 Pro

Here's what you requested:

Code: Select all

TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
SET address {{!EXTRACT}}
PROMPT {{address}}
SET !EXTRACT NULL

TAG POS=1 TYPE=TD ATTR=* EXTRACT=HTM
SET address {{!EXTRACT}}
PROMPT {{address}}
SET !EXTRACT NULL
Output:

Code: Select all

4901 N Harold Ave
						 
						
						 
						
							BERLIN, 
						
						NY 
						54627

Code: Select all

<td>              4901 N Harold Ave
                                      BERLIN,               NY        54627&nbsp;      </td>
Source of information: dentaquest.com provider search
chivracq
Posts: 9317
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Script to remove excess white spaces not working

Post by chivracq » Mon Nov 14, 2016 4:05 am

Loxigan wrote:Hi,

Thanks for the quick reply.

Code: Select all

Imacros version - 8.9.7
FF Version - 49.0.2
OS - Windows 10 Pro 
Here's what you requested:

Code: Select all

TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
SET address {{!EXTRACT}}
PROMPT {{address}}
SET !EXTRACT NULL

TAG POS=1 TYPE=TD ATTR=* EXTRACT=HTM
SET address {{!EXTRACT}}
PROMPT {{address}}
SET !EXTRACT NULL
Output:

Code: Select all

4901 N Harold Ave
						 
						
						 
						
							BERLIN, 
						
						NY 
						54627

Code: Select all

<td>              4901 N Harold Ave
                                      BERLIN,               NY        54627&nbsp;      </td>
Source of information: dentaquest.com provider search
Okay..., oh sorry, first perfect for FCI, your first TXT Extract looks legit indeed, but hum, I've never seen an HTM Extract like your:

Code: Select all

<td>              4901 N Harold Ave
                                      BERLIN,               NY        54627&nbsp;      </td>
Not possible...!, you don't get such a neat Address on 3 Lines from that Source Code, sorry...!
(Or you were just lucky once on some narrow (horizontally) Smartphone..)

Provide the URL to your Site/Page or as mentioned before, upload yourself some HTML Saveas to your Thread otherwise...
I see your "Source of information: dentaquest.com provider search" which I don't understand, we need some exact direct URL to some Page to test your Pb, we can't go searching for hours what "Source of information: dentaquest.com provider search" might need..., pfff...! Sorry losing interest... :roll:
- (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...
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Script to remove excess white spaces not working

Post by iimfun » Mon Nov 14, 2016 8:03 am

It seems to be possible with

Code: Select all

TAG POS=1 TYPE=TD ATTR=* EXTRACT=TXT
SET !EXTRACT EVAL("'{{!EXTRACT}}'.trim().replace(/^\\s+/gm, '');")
Loxigan
Posts: 7
Joined: Wed Nov 09, 2016 5:37 pm

Re: Script to remove excess white spaces not working

Post by Loxigan » Tue Nov 15, 2016 3:24 am

Ok. I'll try this out. I haven't forgotten you chiv :)
chivracq
Posts: 9317
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Script to remove excess white spaces not working

Post by chivracq » Tue Nov 15, 2016 4:30 am

Loxigan wrote:Ok. I'll try this out. I haven't forgotten you chiv :)
OK, but I guess @iimfun's Statement will probably be correct I reckon, he's good with Global 'replace()', ah-ah...! I need to go digging one day in those Regex Expressions... :oops:

But I'm still "suspicious" about the 'EXTRACT=HTM' on your 'TD' Field, it looks very strange to me, with all those Spaces/Tabs, there is maybe some Layout Formatting at some higher Level than your 'TD' Field (but I would need to see the whole Page) but the Web-Designer of that Page went through a lot of hassle to get the Display a bit correct, it can be much more simple... (I would still be interested to have a look at the HTM Structure of that/those Page(s), if you can post the URL... From your "other" Thread, it doesn't look like there is anything "secret" about it...)

As I don't like/master Global 'replace()', I would come up with a much more complicated/cumbersome Solution that @iimfun's one, and I guess I would even need 2 or 3 Examples in total to make sure it works in different cases, so if @iimfun's Solution works, stick to it, ah-ah...!
- (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...
Loxigan
Posts: 7
Joined: Wed Nov 09, 2016 5:37 pm

Re: Script to remove excess white spaces not working

Post by Loxigan » Wed Nov 16, 2016 12:29 am

chivracq wrote:
Loxigan wrote:Ok. I'll try this out. I haven't forgotten you chiv :)
OK, but I guess @iimfun's Statement will probably be correct I reckon, he's good with Global 'replace()', ah-ah...! I need to go digging one day in those Regex Expressions... :oops:

But I'm still "suspicious" about the 'EXTRACT=HTM' on your 'TD' Field, it looks very strange to me, with all those Spaces/Tabs, there is maybe some Layout Formatting at some higher Level than your 'TD' Field (but I would need to see the whole Page) but the Web-Designer of that Page went through a lot of hassle to get the Display a bit correct, it can be much more simple... (I would still be interested to have a look at the HTM Structure of that/those Page(s), if you can post the URL... From your "other" Thread, it doesn't look like there is anything "secret" about it...)

As I don't like/master Global 'replace()', I would come up with a much more complicated/cumbersome Solution that @iimfun's one, and I guess I would even need 2 or 3 Examples in total to make sure it works in different cases, so if @iimfun's Solution works, stick to it, ah-ah...!
Here is the link to the website. The results page does not give me a specific reference to the search criteria in the address bar as in a Get action for their search form, so I will give you the main search page where you can enter your own search criteria.

https://govservices.dentaquest.com/Router.jsp

Would appreciate your feedback. Thanks!
Post Reply