您好,我正在尝试从 html 页面(打印机的静态页面)中选择 4 个值,但我遇到了一些问题。我有一些尝试都失败了,请你们帮助我:
孔页 = http://pastebin.com/e7eKAV0x
意向代码:
<tr>
<td>
Yellow Cartridge
<br>
Order 305A (CE412A)
</td>
<td class="alignRight valignTop">
40%
†
</td>
</tr>
(请使用检查/检查页面)我需要来自 4 个不同字段(打印机颜色)的 40% 值。当颜色消失时 --
我的最后一次尝试:
public void buildCartigesAndValue(String ipString) throws IOException {
LOGGER.log(Level.INFO, "Starting mining over IP " + ipString);
String context = getUrlSource(ipString);
System.out.println(context);
urlPart = "/info_colorUsageJobLog.html?tab=Status&menu=ColorUsageLog";
if (context.contains("HP Color LaserJet CP2025dn") || context.contains("HP Color LaserJet CM2320nf MFP")) {
LOGGER.log(Level.INFO, "PRINTER TYPE ======= HP Color LaserJet CP2025dn");
regexColorContent = "\\w+\\W{1}Cartridge (?<!Printer)";
regexTagContent = "(<td{1}>)([^<]{1}[^.{20}][^ ].*?)(</td>)";
}
else if (context.contains("HP LaserJet 400 color M451dw")){
LOGGER.log(Level.INFO, "PRINTER TYPE ======= HP LaserJet 400 color M451dw");
regexColorContent = "\\w+\\W{1}Cartridge (?<!Printer)";
regexTagContent = "Cartridge.{50}";
}
List<Integer> vals = findCartegisProcentr(context);
List<String> colors = findCartigesColor(context);
for (int i = 0; i < colors.size(); i++) {
if (colors.get(i).contains("Printer")) {
continue;
}
System.out.println(colors.get(i));
addNewColorVal(colors.get(i), vals.get(i));
}
LOGGER.log(Level.INFO, "Stopping sucessfully ---- MAP ---- " + this.colorAmountMap.toString());
}
public List<Integer> findCartegisProcentr(String context) {
List<Integer> vals = new ArrayList<>();
regexValContent = "\\d{2}|-{2}"; // FOR PARTICULAR THE VALUES
Pattern patternTagContent = Pattern.compile(regexTagContent);
Matcher matcherTagContent = patternTagContent.matcher(context);
Pattern patternValContent = Pattern.compile(regexValContent);
while (matcherTagContent.find()) {
Matcher matcherValContent = patternValContent
.matcher(matcherTagContent.group());
matcherValContent.find();
try {
vals.add(Integer.parseInt(matcherValContent.group()));
} catch (Exception e) {
vals.add(0);
}
}
return vals;
}