0

Can anyone tell me which is best to use to extract the following data from a html file which was received with curl .

<script>document.getElementById("test-summary").innerHTML = "<strong>Test Pages:</strong> 1 right, 0 wrong, 0 ignored, 0 exceptions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

I will need only the part where 1 right, 0 wrong, 0 ignored, 0 exceptions . based on the following tag : document.getElementById("test-summary") . These are some test results and I will need to make some logic based on these .

If anyone can give a suggestion on how to do this I would be very grateful .

Many thanks,

Istvan Caluser

  • awk -F '<|>|&' '/test-summary/{print $7}' – Mandar Shinde Aug 18 '15 at 8:45
2

Not super elegant, but here you go:

sed -ne 's/.*"test-summary".* \([0-9][0-9]* right [^&].*exceptions\)&nbsp.*/\1/p'

For example:

$ echo '<script>document.getElementById("test-summary").innerHTML = "<strong>Test Pages:</strong> 1 right, 0 wrong, 0 ignored, 0 exceptions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' | sed -ne 's/.*"test-summary".* \([0-9][0-9]* right,[^&].*exceptions\)&nbsp.*/\1/p'
1 right, 0 wrong, 0 ignored, 0 exceptions
  • It doesn't return anything , and I'm not familiar with sed's syntax . – hoisu Aug 18 '15 at 8:46
  • @CaluserIstvan What are you running? You have to pipe your HTML to that program, or add a command-line parameter that is the name of the file with the HTML output. – user3188445 Aug 18 '15 at 8:49
  • I was trying to run in directly on a file piping it works , thank you very much ! :) – hoisu Aug 18 '15 at 8:54
0

With grep and awk:

grep 'document.getElementById("test-summary")' file.html | awk -F'</strong>|&' '{print $2}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.