Trim leading and trailing spaces

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Trim leading and trailing spaces

by kiz13 on Sat Feb 11, 2017 12:30 pm

good morning friends,
I have the following code


The extraction of this page https://notariad1970.000webhostapp.com/P%C3%A1gina%20Principal.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: Sun Feb 05, 2017 7:36 pm

Re: Trim leading and trailing spaces

by kiz13 on Tue Feb 14, 2017 6:21 am

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: Sun Feb 05, 2017 7:36 pm

Re: Trim leading and trailing spaces

by kiz13 on Tue Feb 14, 2017 1: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
kiz13
 
Posts: 7
Joined: Sun Feb 05, 2017 7:36 pm

Re: Trim leading and trailing spaces

by iimfun on Wed Feb 15, 2017 1:12 am

This should work for you
Code: Select all
SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/\\n/g, '').trim();")
iimfun
 
Posts: 201
Joined: Tue Jul 19, 2016 6:06 am

Re: Trim leading and trailing spaces

by kiz13 on Wed Feb 15, 2017 6:09 am

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"
kiz13
 
Posts: 7
Joined: Sun Feb 05, 2017 7:36 pm

Re: Trim leading and trailing spaces

by iimfun on Thu Feb 16, 2017 12:53 am

Hi, okay, try this way
Code: Select all
SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/\\n/g, '').trim().replace(/\\s*(\\[EXTRACT\\])\\s*/g, '$1');")
iimfun
 
Posts: 201
Joined: Tue Jul 19, 2016 6:06 am

Re: Trim leading and trailing spaces

by kiz13 on Thu Feb 16, 2017 6:08 am

Thank you very much my friend, I am totally thankful
kiz13
 
Posts: 7
Joined: Sun Feb 05, 2017 7:36 pm


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 3 guests

Website Monitoring