Please Help with replace

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.

Please Help with replace

by dionvk on Wed Jun 15, 2016 11:37 am

iMacros Browser v10.0.2.2823
FF 47.0 x86 en-US with iMacros for FF add-on 8.9.7
Win7 x64

Hi, anyone can help me with eval replace?
in firefox it can replace with fine job, but when extract description,it extract to one paragraph.
im trying using imacros browser, it can extract description with multi paragraph but not with replace.
i prefer to use firefox, but not mind if i must use imacros browser to do the job.
My goal is to extract that description into multi paragraph and replace other text im not using.
THX b4!!

Code: Select all
'URL GOTO=https://www.tokopedia.com/kopijayakarta/fiorenza-french-press-coffee-maker-350-ml-for-3-cups
SET !EXTRACT_TEST_POPUP NO
'Set !REPLAYSPEED SLOW
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0

VERSION BUILD=10022823
TAB T=1
'gr
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0 EXTRACT=TXT
SET !VAR1 EVAL("'{{!EXTRACT}}'.replace(/gr/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")
SET !EXTRACT NULL
SET !EXTRACT {{!VAR1}}

'rb
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0<SP>view-count EXTRACT=TXT
SET !VAR2 EVAL("'{{!EXTRACT}}'.replace(/rb/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")
SET !EXTRACT NULL
SET !EXTRACT {{!VAR2}}

SAVEAS TYPE=EXTRACT FOLDER=C:\Users\dion\Documents\iMacros\Macros FILE=Ordereqweqs{{!NOW:dd-mm-yyyy}}.csv
dionvk
 
Posts: 4
Joined: Tue Jun 14, 2016 4:12 am

Re: Please Help with replace

by chivracq on Wed Jun 15, 2016 1:41 pm

dionvk wrote:
Code: Select all
iMacros Browser v10.0.2.2823
FF 47.0 x86 en-US with iMacros for FF add-on 8.9.7
Win7 x64


Hi, anyone can help me with eval replace?
in firefox it can replace with fine job, but when extract description,it extract to one paragraph.
im trying using imacros browser, it can extract description with multi paragraph but not with replace.
i prefer to use firefox, but not mind if i must use imacros browser to do the job.
My goal is to extract that description into multi paragraph and replace other text im not using.
THX b4!!

Code: Select all
'URL GOTO=https://www.tokopedia.com/kopijayakarta/fiorenza-french-press-coffee-maker-350-ml-for-3-cups
SET !EXTRACT_TEST_POPUP NO
'Set !REPLAYSPEED SLOW
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0

VERSION BUILD=10022823
TAB T=1
'gr
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0 EXTRACT=TXT
SET !VAR1 EVAL("'{{!EXTRACT}}'.replace(/gr/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")
SET !EXTRACT NULL
SET !EXTRACT {{!VAR1}}

'rb
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0<SP>view-count EXTRACT=TXT
SET !VAR2 EVAL("'{{!EXTRACT}}'.replace(/rb/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")
SET !EXTRACT NULL
SET !EXTRACT {{!VAR2}}

SAVEAS TYPE=EXTRACT FOLDER=C:\Users\dion\Documents\iMacros\Macros FILE=Ordereqweqs{{!NOW:dd-mm-yyyy}}.csv

Hum, I had a look at your Site and your Script and your 'EVAL()' + 'replace()' Statements just look fine to me even if a bit more "standard" way to build your '!EXTRACT' for the 'SAVEAS' would be more like this (and your 'replace()' Statements are a bit cumbersome and nearly "too powerful" for your Need, but OK, they work...):
Code: Select all
VERSION BUILD=8820413 RECORDER=FX

'SET !ERRORIGNORE YES
TAB T=1
'SET !EXTRACT_TEST_POPUP NO

URL GOTO=https://www.tokopedia.com/kopijayakarta/fiorenza-french-press-coffee-maker-350-ml-for-3-cups
'Set !REPLAYSPEED SLOW
SET !TIMEOUT_STEP 0

'gr
SET !EXTRACT NULL
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0 EXTRACT=TXT
SET !VAR1 EVAL("'{{!EXTRACT}}'.replace(/gr/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR><BR>VAR1:<SP>_{{!VAR1}}_

'rb
SET !EXTRACT NULL
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0<SP>view-count EXTRACT=TXT
SET !VAR2 EVAL("'{{!EXTRACT}}'.replace(/rb/g, '');")
'SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/\rb/g,' ')")

SET !EXTRACT {{!VAR1}}
ADD !EXTRACT {{!VAR2}}
PROMPT VAR1:<SP>_{{!VAR1}}_<BR><BR>VAR2:<SP>_{{!VAR2}}_<BR><BR>EXTRACT:<SP>_{{!EXTRACT}}_

PAUSE
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\dion\Documents\iMacros\Macros FILE=Ordereqweqs{{!NOW:dd-mm-yyyy}}.csv
(Tested on iMacros for FF v8.8.2, Pale Moon v26.1.1 (=FF43), Win10-x64_ENG-US.)

The 2nd PROMPT will display the following Info, which is actually the same Result like you already had...:
VAR1: _1.000_

VAR2: _5,5_

EXTRACT: _1.000[EXTRACT]5,5_

iMacros for FF will then save the Data in your '.CSV' like:
"1.000","5,5"
While when saving the Data to your '.CSV' from iMB, it uses the Separator and Delimiter specified in your OS Regional Settings and iMB usually doesn't use any Double Quotes.

What I understand about your "one/multi paragraph" is that when you open your '.CSV' File from Excel I guess, both Extracts are displayed in the same Cell, this is probably because you don't have the Double Quotes and/or the Comma specified as the Delimiter/Separator in the Excel Options for importing/opening '.CSV' Files.

Have a look at your Regional Settings, you might have the Semi-Colon (instead of the Comma) specified as the Delimiter, on iMacros for FF you can then use '!DATASOURCE_DELIMITER' to use a Semi-Colon as well...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6479
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Please Help with replace

by dionvk on Thu Jun 16, 2016 1:42 pm

ur code r awesome!
but i need somemore enlightenment.
about new paragraph its not what u think, its like this:
Image

And i had a new case.
i had a few extracted text at the beginning, and at near end i had 2 replace().
i tried ur code but it only save 2 value.
Code: Select all
'SET !ERRORIGNORE YES
TAB T=1
SET !EXTRACT_TEST_POPUP NO

URL GOTO=https://www.tokopedia.com/kopijayakarta/fiorenza-french-press-coffee-maker-350-ml-for-3-cups
'Set !REPLAYSPEED SLOW
SET !TIMEOUT_STEP 0

'-----------New Case---------
'some example text extract
TAG POS=1 TYPE=DT ATTR=CLASS:pull-left EXTRACT=TXT
TAG POS=1 TYPE=DT ATTR=CLASS:pull-left<SP>ml-10 EXTRACT=TXT
'----------------------------

'gr
SET !EXTRACT NULL
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0 EXTRACT=TXT
SET !VAR1 EVAL("'{{!EXTRACT}}'.replace(/gr/g, '');")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR><BR>VAR1:<SP>_{{!VAR1}}_

'rb
SET !EXTRACT NULL
TAG POS=1 TYPE=DD ATTR=CLASS:pull-left<SP>m-0<SP>view-count EXTRACT=TXT
SET !VAR2 EVAL("'{{!EXTRACT}}'.replace(/rb/g, '');")

SET !EXTRACT {{!VAR1}}
ADD !EXTRACT {{!VAR2}}
PROMPT VAR1:<SP>_{{!VAR1}}_<BR><BR>VAR2:<SP>_{{!VAR2}}_<BR><BR>EXTRACT:<SP>_{{!EXTRACT}}_


SAVEAS TYPE=EXTRACT FOLDER=C:\Users\dion\Documents\iMacros\Macros FILE=Oreqweqs.csv


NB: if u had a time, could you please explain why it needed to use this 2 line again?
Code: Select all
SET !EXTRACT {{!VAR1}}
ADD !EXTRACT {{!VAR2}}

if not its ok, i'll just use ur script directly.
anyway thanks a lot!
dionvk
 
Posts: 4
Joined: Tue Jun 14, 2016 4:12 am

Re: Please Help with replace

by dionvk on Mon Jun 20, 2016 1:32 am

anyone can help???
dionvk
 
Posts: 4
Joined: Tue Jun 14, 2016 4:12 am

Re: Please Help with replace

by chivracq on Mon Jun 20, 2016 1:53 pm

dionvk wrote:anyone can help???

Hum, I had not noticed (yet) your previous Post, as I'm always a bit busy during WE's...

But, hum, I wanted to have another look at your Site but it seems to be in Maintenance right now, I'll try later...
Sedang Dalam Perbaikan

Dear Toppers.

Dalam upaya kami meningkatkan kualitas layanan, Tokopedia saat ini sedang melakukan maintenance.

Selama masa maintenance, Tokopedia tidak dapat diakses untuk sementara waktu. Mohon maaf atas ketidaknyamanannya. Terima kasih atas pengertiannya.

Kami akan segera kembali.
Terima kasih.


OK, I understand now better what you meant with "Paragraph", I only referred to your original Script which only contained 2 Sections (and only 2 Extracts) for the 'gr' & 'rb' Fields...

dionvk wrote:NB: if u had a time, could you please explain why it needed to use this 2 line again?
Code: Select all
SET !EXTRACT {{!VAR1}}
ADD !EXTRACT {{!VAR2}}

if not its ok, i'll just use ur script directly.
anyway thanks a lot!

What it does is storing the Content of '!EXTRACT' in some Temp_Var to reconstruct '!EXTRACT' after each Extraction little by little, or at the end just before doing the 'SAVEAS' because you need to set '!EXTRACT' to "NULL" before doing each new Extract.
And it's easier and more reliable to let iMacros rebuild the Content of '!EXTRACT' with 'SET' and 'ADD' after each Extraction to perform any Data/String Manipulation like you need for 'gr' and 'rb' than trying to manipulate the complete '!EXTRACT' like you were doing. You managed to get it to work, but it's pretty "dangerous", especially with global 'replace()' because it will also apply to the previous Extracts and that might have some undesirable Effects...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6479
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Please Help with replace

by dionvk on Thu Jun 23, 2016 12:17 am

thanks for ur explanation 8)
anw it seems that site already up, can u pls check again?
thx
dionvk
 
Posts: 4
Joined: Tue Jun 14, 2016 4:12 am


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 3 guests

-->