Search code examples
imacros

Replace specific URL with a null value


I want to replace the URL if its https://en.wikipedia.org/wiki/0/ to replace with "null"

       url goto={{!col4}}
       ADD !EXTRACT {{!col4}}
       TAG POS=1 TYPE=SPAN ATTR=CLASS:value<SP>block<SP>dark-gray EXTRACT=TXT
       TAG POS=2 TYPE=SPAN ATTR=CLASS:value<SP>block<SP>dark-gray EXTRACT=TXT 
       TAG POS=1 TYPE=SPAN ATTR=CLASS:value EXTRACT=TXT
       SET !EXTRACT EVAL({{!EXTRACT}}'.replace(/https://en.wikipedia.org/wiki/0//g, '').replace(/\\[EXTRACT\\]/g, 'null');")
       wait seconds=3
       SAVEAS TYPE=EXTRACT FOLDER=* FILE=test3.csv

Tried the above code but does not work for me


Solution

  • Try the following way:

    url goto={{!col4}}
    ADD !EXTRACT EVAL("'{{!URLCURRENT}}' == 'https://en.wikipedia.org/wiki/0/' ? 'null' : '{{!URLCURRENT}}';")
    TAG POS=1 TYPE=SPAN ATTR=CLASS:value<SP>block<SP>dark-gray EXTRACT=TXT
    TAG POS=2 TYPE=SPAN ATTR=CLASS:value<SP>block<SP>dark-gray EXTRACT=TXT 
    TAG POS=1 TYPE=SPAN ATTR=CLASS:value EXTRACT=TXT
    wait seconds=3
    SAVEAS TYPE=EXTRACT FOLDER=* FILE=test3.csv