Добрый день.
Задача - распарсить страничку получаемую HTTP агентом с устройства. Вот код странички:
<form method="post" action="/etc/mnt_info.csv"><div><input type="hidden" id="pageid" name="pageid" value="3" /></div><div class="contentsGroup"><h3>Node Information</h3><dl class="items"><dt>Model Name</dt><dd>Brother HL-3170CDW series</dd><dt>Serial no.</dt><dd>E71798E7J179601</dd><dt>Main Firmware Version</dt><dd>1.28</dd><dt>Sub1 Firmware Version</dt><dd>1.06</dd><dt>Memory Size</dt><dd>128<span class="unit">MB</span></dd></dl></div><div class="contentsGroup"><h3>Device Status</h3><dl class="items"><dt>Page Counter</dt><dd>10388</dd><dt class="subhead"><span>Color</span></dt><dd>9346</dd><dt class="subhead"><span>B&W</span></dt><dd>1042</dd><dt>Image Count Total</dt><dd>37123</dd><dt class="subhead"><span>Cyan</span></dt><dd>8880</dd><dt class="subhead"><span>Magenta</span></dt><dd>8889</dd><dt class="subhead"><span>Yellow</span></dt><dd>9109</dd><dt class="subhead"><span>Black</span></dt><dd>10245</dd><dt>Drum Count</dt><dd></dd><dt class="subhead"><span>Cyan</span></dt><dd>10388</dd><dt class="subhead"><span>Magenta</span></dt><dd>10388</dd><dt class="subhead"><span>Yellow</span></dt><dd>10388</dd><dt class="subhead"><span>Black</span></dt><dd>10388</dd></dl></div><div class="contentsGroup"><h3>Remaining Life</h3><dl class="items"><dt>Drum Unit Cyan (C)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Magenta (M)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Yellow (Y)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Black (BK)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Belt Unit</dt><dd>35871<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(72.00%)</dd><dt>Fuser Unit</dt><dd>39612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(80.00%)</dd><dt>Paper Feeding Kit 1</dt><dd>39823<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(80.00%)</dd><dt>Toner Cyan (C)**</dt><dd>(90.00%)</dd><dt>Toner Magenta (M)**</dt><dd>(70.00%)</dd><dt>Toner Yellow (Y)**</dt><dd>(80.00%)</dd><dt>Toner Black (BK)**</dt><dd>(10.00%)</dd></dl></div><div class="contentsGroup"><h3>Total Pages Printed</h3><dl class="items"><dt>A4/Letter</dt><dd>10375<span class="unit">pages</span></dd><dt>Legal/Folio</dt><dd>0<span class="unit">pages</span></dd><dt>B5/Executive</dt><dd>4<span class="unit">pages</span></dd><dt>Envelopes</dt><dd>0<span class="unit">pages</span></dd><dt>A5</dt><dd>0<span class="unit">pages</span></dd><dt>Others</dt><dd>9<span class="unit">pages</span></dd></dl></div><div class="contentsGroup"><h3>Total Pages Printed</h3><dl class="items"><dt>Plain/Thin/Recycled</dt><dd>10381<span class="unit">pages</span></dd><dt>Thick/Thicker/Bond</dt><dd>7<span class="unit">pages</span></dd><dt>Envelopes/Env. Thick/Env. Thin</dt><dd>0<span class="unit">pages</span></dd><dt>Label</dt><dd>0<span class="unit">pages</span></dd><dt>Hagaki</dt><dd>0<span class="unit">pages</span></dd><dt>Glossy</dt><dd>0<span class="unit">pages</span></dd></dl></div><div class="contentsGroup"><h3>Replace Count</h3><dl class="items"><dt>Toner Cyan (C)</dt><dd>5</dd><dt>Toner Magenta (M)</dt><dd>7</dd><dt>Toner Yellow (Y)</dt><dd>7</dd><dt>Toner Black (BK)</dt><dd>7</dd><dt>Drum Unit Cyan (C)</dt><dd>0</dd><dt>Drum Unit Magenta (M)</dt><dd>0</dd><dt>Drum Unit Yellow (Y)</dt><dd>0</dd><dt>Drum Unit Black (BK)</dt><dd>0</dd><dt>Belt Unit</dt><dd>0</dd><dt>Fuser Unit</dt><dd>0</dd><dt>Paper Feeding Kit 1</dt><dd>0</dd><dt>Waste Toner Box</dt><dd>0</dd></dl></div><div class="contentsGroup"><dl class="items"><dt>Total Paper Jams</dt><dd>12</dd></dl><dl class="items"><dt>Jam Manual Feed</dt><dd>0</dd><dt>Jam Tray 1</dt><dd>2</dd><dt>Jam Inside</dt><dd>6</dd><dt>Jam Rear</dt><dd>2</dd><dt>Jam 2-sided</dt><dd>2</dd></dl></div><div class="contentsGroup"><h3>Error History(last 10 errors)</h3><table class="list errorHistory" summary="Error History"><tbody><tr><th>1</th><td>Toner Low: BK</td><td>Page : 10274</td></tr><tr><th>2</th><td>Drum !</td><td>Page : 10141</td></tr><tr><th>3</th><td>Drum !</td><td>Page : 10141</td></tr><tr><th>4</th><td>Toner Low: C</td><td>Page : 9982</td></tr><tr><th>5</th><td>Toner Low: Y</td><td>Page : 9824</td></tr><tr><th>6</th><td>Replace Toner (M)</td><td>Page : 9715</td></tr><tr><th>7</th><td>Toner Low: M</td><td>Page : 9468</td></tr><tr><th>8</th><td>Drum !</td><td>Page : 9382</td></tr><tr><th>9</th><td>Drum !</td><td>Page : 9373</td></tr><tr><th>10</th><td>Drum !</td><td>Page : 9373</td></tr></tbody></table></div><div class="contentsGroup"><p class="noteMessage">*Based on A4/Letter printing<br />**Remaining life will vary depending on the types of documents printed, their coverage and device usage.<br /></p></div><div class="contentsGroup"><p class="noteMessage">You can convert this Maintenance Information page to a CSV file format.<br />Click Submit to create the CSV file</p></div><div class="contentsButtons"><input type="submit" value="Submit" /></div></form></div></div></div></div></div><div id="mainFrameBottomLeft"><div id="mainFrameBottomRight"><div id="mainFrameBottomInner"></div></div></div></div><div id="footerFrameContainer"><div id="copyright">Copyright(C) 2000-2013 Brother Industries, Ltd. All Rights Reserved.</div><div id="topBack"><a href="#">Top<img src="/common/images/ic_pt.gif" alt="Top" /></a></div></div></div></div></body></html>
Вот регулярное выражение: Color\D+(\d+) Прекрасно проходит тест и без проблем и собирает данные.
Вот аналогичное выражение: B&D\D+(\d+) Тест проходит в zabbix, тест проходит на сайте https://regex101.com В реальности это просто зависимый элемент данных, ему на вход поступает именно текст приведённый выше. Результат Failed: Cannot perform regular expression "B&D\D+(\d+)" match for value of type "string": pattern does not match
Во ещё, два шага: 1. Drum Unit Black \(BK\)\*(.+) 2. Remaining\)<\/dt><dd>\((\d+) Тест проходит в zabbix и по отдельности и в два шага. В реальном сборе данных та же ошибка.
Вот такое выражение Y\)\*\*<\/dt><dd>\((\d*) прекрасно работает.
Не понимаю, где я заблуждаюсь/ Тесты проходят на реальных данных, а получит данные в online не могу.
Задача - распарсить страничку получаемую HTTP агентом с устройства. Вот код странички:
<form method="post" action="/etc/mnt_info.csv"><div><input type="hidden" id="pageid" name="pageid" value="3" /></div><div class="contentsGroup"><h3>Node Information</h3><dl class="items"><dt>Model Name</dt><dd>Brother HL-3170CDW series</dd><dt>Serial no.</dt><dd>E71798E7J179601</dd><dt>Main Firmware Version</dt><dd>1.28</dd><dt>Sub1 Firmware Version</dt><dd>1.06</dd><dt>Memory Size</dt><dd>128<span class="unit">MB</span></dd></dl></div><div class="contentsGroup"><h3>Device Status</h3><dl class="items"><dt>Page Counter</dt><dd>10388</dd><dt class="subhead"><span>Color</span></dt><dd>9346</dd><dt class="subhead"><span>B&W</span></dt><dd>1042</dd><dt>Image Count Total</dt><dd>37123</dd><dt class="subhead"><span>Cyan</span></dt><dd>8880</dd><dt class="subhead"><span>Magenta</span></dt><dd>8889</dd><dt class="subhead"><span>Yellow</span></dt><dd>9109</dd><dt class="subhead"><span>Black</span></dt><dd>10245</dd><dt>Drum Count</dt><dd></dd><dt class="subhead"><span>Cyan</span></dt><dd>10388</dd><dt class="subhead"><span>Magenta</span></dt><dd>10388</dd><dt class="subhead"><span>Yellow</span></dt><dd>10388</dd><dt class="subhead"><span>Black</span></dt><dd>10388</dd></dl></div><div class="contentsGroup"><h3>Remaining Life</h3><dl class="items"><dt>Drum Unit Cyan (C)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Magenta (M)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Yellow (Y)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Drum Unit Black (BK)*</dt><dd>4612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(31.00%)</dd><dt>Belt Unit</dt><dd>35871<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(72.00%)</dd><dt>Fuser Unit</dt><dd>39612<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(80.00%)</dd><dt>Paper Feeding Kit 1</dt><dd>39823<span class="unit">pages</span></dd><dt>(% of Life Remaining)</dt><dd>(80.00%)</dd><dt>Toner Cyan (C)**</dt><dd>(90.00%)</dd><dt>Toner Magenta (M)**</dt><dd>(70.00%)</dd><dt>Toner Yellow (Y)**</dt><dd>(80.00%)</dd><dt>Toner Black (BK)**</dt><dd>(10.00%)</dd></dl></div><div class="contentsGroup"><h3>Total Pages Printed</h3><dl class="items"><dt>A4/Letter</dt><dd>10375<span class="unit">pages</span></dd><dt>Legal/Folio</dt><dd>0<span class="unit">pages</span></dd><dt>B5/Executive</dt><dd>4<span class="unit">pages</span></dd><dt>Envelopes</dt><dd>0<span class="unit">pages</span></dd><dt>A5</dt><dd>0<span class="unit">pages</span></dd><dt>Others</dt><dd>9<span class="unit">pages</span></dd></dl></div><div class="contentsGroup"><h3>Total Pages Printed</h3><dl class="items"><dt>Plain/Thin/Recycled</dt><dd>10381<span class="unit">pages</span></dd><dt>Thick/Thicker/Bond</dt><dd>7<span class="unit">pages</span></dd><dt>Envelopes/Env. Thick/Env. Thin</dt><dd>0<span class="unit">pages</span></dd><dt>Label</dt><dd>0<span class="unit">pages</span></dd><dt>Hagaki</dt><dd>0<span class="unit">pages</span></dd><dt>Glossy</dt><dd>0<span class="unit">pages</span></dd></dl></div><div class="contentsGroup"><h3>Replace Count</h3><dl class="items"><dt>Toner Cyan (C)</dt><dd>5</dd><dt>Toner Magenta (M)</dt><dd>7</dd><dt>Toner Yellow (Y)</dt><dd>7</dd><dt>Toner Black (BK)</dt><dd>7</dd><dt>Drum Unit Cyan (C)</dt><dd>0</dd><dt>Drum Unit Magenta (M)</dt><dd>0</dd><dt>Drum Unit Yellow (Y)</dt><dd>0</dd><dt>Drum Unit Black (BK)</dt><dd>0</dd><dt>Belt Unit</dt><dd>0</dd><dt>Fuser Unit</dt><dd>0</dd><dt>Paper Feeding Kit 1</dt><dd>0</dd><dt>Waste Toner Box</dt><dd>0</dd></dl></div><div class="contentsGroup"><dl class="items"><dt>Total Paper Jams</dt><dd>12</dd></dl><dl class="items"><dt>Jam Manual Feed</dt><dd>0</dd><dt>Jam Tray 1</dt><dd>2</dd><dt>Jam Inside</dt><dd>6</dd><dt>Jam Rear</dt><dd>2</dd><dt>Jam 2-sided</dt><dd>2</dd></dl></div><div class="contentsGroup"><h3>Error History(last 10 errors)</h3><table class="list errorHistory" summary="Error History"><tbody><tr><th>1</th><td>Toner Low: BK</td><td>Page : 10274</td></tr><tr><th>2</th><td>Drum !</td><td>Page : 10141</td></tr><tr><th>3</th><td>Drum !</td><td>Page : 10141</td></tr><tr><th>4</th><td>Toner Low: C</td><td>Page : 9982</td></tr><tr><th>5</th><td>Toner Low: Y</td><td>Page : 9824</td></tr><tr><th>6</th><td>Replace Toner (M)</td><td>Page : 9715</td></tr><tr><th>7</th><td>Toner Low: M</td><td>Page : 9468</td></tr><tr><th>8</th><td>Drum !</td><td>Page : 9382</td></tr><tr><th>9</th><td>Drum !</td><td>Page : 9373</td></tr><tr><th>10</th><td>Drum !</td><td>Page : 9373</td></tr></tbody></table></div><div class="contentsGroup"><p class="noteMessage">*Based on A4/Letter printing<br />**Remaining life will vary depending on the types of documents printed, their coverage and device usage.<br /></p></div><div class="contentsGroup"><p class="noteMessage">You can convert this Maintenance Information page to a CSV file format.<br />Click Submit to create the CSV file</p></div><div class="contentsButtons"><input type="submit" value="Submit" /></div></form></div></div></div></div></div><div id="mainFrameBottomLeft"><div id="mainFrameBottomRight"><div id="mainFrameBottomInner"></div></div></div></div><div id="footerFrameContainer"><div id="copyright">Copyright(C) 2000-2013 Brother Industries, Ltd. All Rights Reserved.</div><div id="topBack"><a href="#">Top<img src="/common/images/ic_pt.gif" alt="Top" /></a></div></div></div></div></body></html>
Вот регулярное выражение: Color\D+(\d+) Прекрасно проходит тест и без проблем и собирает данные.
Вот аналогичное выражение: B&D\D+(\d+) Тест проходит в zabbix, тест проходит на сайте https://regex101.com В реальности это просто зависимый элемент данных, ему на вход поступает именно текст приведённый выше. Результат Failed: Cannot perform regular expression "B&D\D+(\d+)" match for value of type "string": pattern does not match
Во ещё, два шага: 1. Drum Unit Black \(BK\)\*(.+) 2. Remaining\)<\/dt><dd>\((\d+) Тест проходит в zabbix и по отдельности и в два шага. В реальном сборе данных та же ошибка.
Вот такое выражение Y\)\*\*<\/dt><dd>\((\d*) прекрасно работает.
Не понимаю, где я заблуждаюсь/ Тесты проходят на реальных данных, а получит данные в online не могу.
Comment