iMacros / Firefox / format result

限于喜欢 提交于 2019-12-11 04:21:17

问题


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:


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";


来源:https://stackoverflow.com/questions/16892124/imacros-firefox-format-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!