iMacros / Firefox / format result

2019-08-12 16:42发布

I'm trying to extract some part of a website with this (simplified) code in javascript.

macro2 = "CODE:";
macro2 += "TAG POS={{i}} TYPE=H2 ATTR=TXT:* EXTRACT=TXT" + "\n";
macro2 += "SAVEAS TYPE=EXTRACT FOLDER=U:\imacros FILE=test.csv" + "\n";

So, I get the right values and the are saved in the csv. So far no problem. But the markup of the website is:

<h2>
    content
</h2>

So, each value in my csv is added with an extra hard return. Is there any way to avoid this? With some HTML tag stripping or something?

Any input will be much appreciated! Thank you. /jurgen

1条回答
Deceive 欺骗
2楼-- · 2019-08-12 17:24

put this between the line 2 and 3:

macro2 += 'SET !EXTRACT EVAL("var text=\\"{{!EXTRACT}}\\";var text = text.replace(\'\\\\n\',\'\',\'g\');text;")' + "\n";

or shorter:

macro2 += 'SET !EXTRACT EVAL("var text=\\"{{!EXTRACT}}\\";var text = text.trim();text;")' + "\n";
查看更多
登录 后发表回答