令牌解析错误:词法错误

时间:2015-06-11 00:15:05

标签: jmeter beanshell

当我使用BeanshellPostProcessor来正则表达一些数据并写入文件时,我收到以下错误:

2015/06/11 12:11:19 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``    import java.io.FileOutputStream;     import java.util.Map;     import java.u . . . '' Token Parsing Error: Lexical error at line 10, column 45.  Encountered: "d" (100), after : "\"c:\\" 
2015/06/11 12:11:19 WARN  - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``    import java.io.FileOutputStream;     import java.util.Map;     import java.u . . . '' Token Parsing Error: Lexical error at line 10, column 45.  Encountered: "d" (100), after : "\"c:\\" 

我的代码:

import java.io.FileOutputStream;
import java.util.Map;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;

String entirePage = new String(data);

FileWriter fstream = new FileWriter("c:\\downloads\\results.txt",true);
BufferedWriter out = new BufferedWriter(fstream);

Pattern totalNetValue = Pattern.compile("totalNetValue\">([^\"]+)</span>");

Matcher mTotalNetValue = totalNetValue.matcher(entirePage);
    mTotalNetValue.find();
//out.write(${date});
    out.write(mTotalNetValue.group(1));
out.write("\n");

out.close();

任何想法我的代码有什么问题?谢谢: - )

1 个答案:

答案 0 :(得分:2)

如何将代码读入bsh解释器?确实看起来双反斜杠减少为单反斜杠。

作为快速修复,只需使用正斜杠而不是反斜杠,例如

FileWriter fstream = new FileWriter("c:/downloads/results.txt",true);