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

1
  • awk -F '<|>|&' '/test-summary/{print $7}' Aug 18, 2015 at 8:45

2 Answers 2

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
3
  • It doesn't return anything , and I'm not familiar with sed's syntax .
    – hoisu
    Aug 18, 2015 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. Aug 18, 2015 at 8:49
  • I was trying to run in directly on a file piping it works , thank you very much ! :)
    – hoisu
    Aug 18, 2015 at 8:54
0

With grep and awk:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .