Trim leading and trailing spaces

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
kiz13
Posts: 7
Joined: Mon Feb 06, 2017 2:36 am

Trim leading and trailing spaces

Post by kiz13 » Sat Feb 11, 2017 7:30 pm

good morning friends,
I have the following code


The extraction of this page https://notariad1970.000webhostapp.com/ ... cipal.html

Code: Select all

VERSION BUILD=844 RECORDER=CR
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:form1 ATTR=ID:* EXTRACT=TXT
TAG POS=1 TYPE=SPAN ATTR=ID:lblFechaSistema EXTRACT=TXT
TAG POS=1 TYPE=TD ATTR=TXT:Fecha<SP>de<SP>Registro
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\oz\Downloads FILE=1 

The result of the extraction is as follows

Code: Select all

54001333300120140059801,"miércoles, 08 de febrero de 2017 - 09:14:55 p.m.","
15 Sep 2015 
","
ENVIO EXPEDIENTE DESPACHO DE ORIGEN 
","
MEDIANTE OFICIO M-9186 SE DEVUELVE EL EXPEDIENTE AL JUZGADO DE ORIGEN. 
","

","

","
15 Sep 2015 
"
But I want to eliminate spaces and jumps, so that it stays this way

Code: Select all

54001333300120140059801,"miércoles, 08 de febrero de 2017 - 09:14:55 p.m.","15 Sep 2015","ENVIO EXPEDIENTE DESPACHO DE ORIGEN","MEDIANTE OFICIO M-9186 SE DEVUELVE EL EXPEDIENTE AL JUZGADO DE ORIGEN.","","","15 Sep 2015"

I try this code eva, but it did not work

Code: Select all

SET !EXTRACT "    This value has leading and trailing spaces     "
' Display the value within vertical bars to emphasize the spaces
PROMPT |{{!EXTRACT}}|
SET trimmedValue EVAL("\"{{!EXTRACT}}\".replace(/^\\s*|\\s*$/g, \"\");")
PROMPT "|{{trimmedValue}}| - not anymore!"
kiz13
Posts: 7
Joined: Mon Feb 06, 2017 2:36 am

Re: Trim leading and trailing spaces

Post by kiz13 » Tue Feb 14, 2017 1:21 pm

Should I use a variable to replace, the text "extract" by the contents of this field

Code: Select all

"    This value has leading and trailing spaces     "
kiz13
Posts: 7
Joined: Mon Feb 06, 2017 2:36 am

Re: Trim leading and trailing spaces

Post by kiz13 » Tue Feb 14, 2017 8:09 pm

I try this way,
But I do not save anything in the cvs

Code: Select all

SET !VAR1 {{!EXTRACT}} 
SET !EXTRACT NULL
SET !EXTRACT {{!VAR1}}
' Display the value within vertical bars to emphasize the spaces
PROMPT |{{!EXTRACT}}|
SET trimmedValue EVAL("\"{{!EXTRACT}}\".replace(/^\\s*|\\s*$/g, \"\");")
PROMPT "|{{trimmedValue}}| - not anymore!"

SAVEAS TYPE=EXTRACT FOLDER=C:\Users\13 FILE=1
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Trim leading and trailing spaces

Post by iimfun » Wed Feb 15, 2017 8:12 am

This should work for you

Code: Select all

SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/\\n/g, '').trim();")
kiz13
Posts: 7
Joined: Mon Feb 06, 2017 2:36 am

Re: Trim leading and trailing spaces

Post by kiz13 » Wed Feb 15, 2017 1:09 pm

Hi, my friend, thank you very much for your contribution, try your code and I eliminate the final spaces very well, but I do not eliminate the initial spaces.

Code: Select all

miércoles, 08 de febrero de 2017 - 09:14:55 p.m.,"                                                                    15 Sep 2015","                                                                    ENVIO EXPEDIENTE DESPACHO DE ORIGEN","                                                                    MEDIANTE OFICIO M-9186 SE DEVUELVE EL EXPEDIENTE AL JUZGADO DE ORIGEN.","","","                                                                    15 Sep 2015"
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Trim leading and trailing spaces

Post by iimfun » Thu Feb 16, 2017 7:53 am

Hi, okay, try this way

Code: Select all

SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/\\n/g, '').trim().replace(/\\s*(\\[EXTRACT\\])\\s*/g, '$1');")
kiz13
Posts: 7
Joined: Mon Feb 06, 2017 2:36 am

Re: Trim leading and trailing spaces

Post by kiz13 » Thu Feb 16, 2017 1:08 pm

Thank you very much my friend, I am totally thankful
Post Reply