A much cleaner way of doing this is creating a css for media type of print. In other words, take your existing CSS document, and copy it. Remove (you can set to visibility to hidden) anything you don't want to print (advertisements, headers, footers, menus, whatever). Set the Media property in your <link href="./linktoprint.css" media="print"/>.
Then when a user clicks the print button, you can just have it call a javascript print method. That way you don't need to worry about parsing out a ton of data.
Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.