Created
          June 28, 2016 17:29 
        
      - 
      
 - 
        
Save eliasdorneles/64a0a62e5473ac6bf39d9dc5c39c0eac to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | >>> js_with_html_comments = u'<!-- some... --> alert("oi"); <!-- ...comments -->' | |
| >>> import js2xml | |
| >>> from lxml import etree | |
| >>> def strip_comments(js): | |
| ....: node = etree.fromstring(u'<node>%s</node>' % js) | |
| ....: etree.strip_tags(node, etree.Comment) | |
| ....: return node.text | |
| ....: | |
| >>> strip_comments(js_with_html_comments) | |
| ' alert("oi"); ' | |
| >>> js2xml.parse(strip_comments(js_with_html_comments)) | |
| <Element program at 0x7fca876e6d88> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment