Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7367919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:35:54+00:00 2026-05-29T03:35:54+00:00

Trying to process a very simple html5 script and render it using html5lib import

  • 0

Trying to process a very simple html5 script and render it using html5lib

import html5lib

html = '''<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Hi</title>
    </head>
    <body>
        <script src="a.js"></script>
        <script src="b.js"></script>
    </body>
</html>
'''

parser = html5lib.HTMLParser(tree = html5lib.treebuilders.getTreeBuilder("lxml"))
walker = html5lib.treewalkers.getTreeWalker("lxml")
serializer = html5lib.serializer.htmlserializer.HTMLSerializer()

document = parser.parse(html)
stream = walker(document)
theHTML = serializer.render(stream)

print theHTML

The output looks like:

<!DOCTYPE html><html lang=en><head>
        <title>Hi</title>
    </head>
    <body>
        <script src=a.js></script>
        <script src=b.js></script>

Yup. It just cuts off mid way. Changing the tree builder from lxml to dom does nothing. Tweaking the HTML changes the output but it’s still pretty corrupt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:35:55+00:00Added an answer on May 29, 2026 at 3:35 am

    So the key seems to be omit_optional_tags=False somehow with that missing it eats the end of the output.

    parser = html5lib.HTMLParser(tree = html5lib.treebuilders.getTreeBuilder("lxml"))
    document = parser.parse(html)    
    walker = html5lib.treewalkers.getTreeWalker("lxml")
    stream = walker(document)
    s = serializer.htmlserializer.HTMLSerializer(omit_optional_tags=False)
    output_generator = s.serialize(stream)
    for item in output_generator:
             print item
    
    
    <!DOCTYPE html>
    <html lang=en>
    <head>
    
    
    <title>
    Hi
    </title>
    
    
    </head>
    
    
    <body>
    
    
    <script src=a.js>
    </script>
    
    
    <script src=b.js>
    </script>
    
    
    
    
    </body>
    </html>
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails: 3.0.3 Ruby: 1.9.2 Trying to deserialize a very simple object using YAML.load or
I'm trying a very simple process of adding a row to a GoogleDocs spreadsheet
I'm very early in the iPhone development learning process. I'm trying to get my
I am trying to process an uploaded file in a Perl program, using CGI::Application.
I am trying to process a dimension using SQL Server 2005 Analysis Services .
All I'm trying to do is open a very simple application that is supposed
I'm trying to use NServiceBus to send messages from a console process (very similar
I am trying to provide a very simple Do you wish to save this
I am trying to achieve a very simple thing in MATLAB. I have a
I'm in the process of learning HTML5 (and OO Javascript) and am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.