Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect HTML for empty <script> tags #90

Open
asouchang opened this issue Dec 1, 2014 · 3 comments
Open

Incorrect HTML for empty <script> tags #90

asouchang opened this issue Dec 1, 2014 · 3 comments

Comments

@asouchang
Copy link

The following python code generates incorrect HTML code for empty script tags.

print PyQuery('<script></script>')

The expected output is exactly the input string. However, the actual output is

<script/>

Testing Environment:
OS: Mac OS X 10.10
Python: 2.7.6 (shipped with OS)
PyQuery: 1.2.9 (installed from pip)

@Lhfcws
Copy link

Lhfcws commented Jan 4, 2015

I've got the same problem.

I tested the latest version on github. It is still failed.

Actually, I think it is due to lxml.

I tried

    PyQuery("<div></div>")    # output: <div/>

For user, it may be a bug.

A trick is that you can insert some useless js into the script tag to make it works correctly, like

    <script> var __pyquery = 0;</script>

@twz915
Copy link

twz915 commented Jan 11, 2015

doc = PyQuery('<script></script>')
print doc.outer_html()

works well

@gawel gawel mentioned this issue Jan 19, 2015
@mrnfrancesco
Copy link

Even if this bug/conversation seems dead:

PyQuery('<script></script>').html() should not be equal to <script></script>, but it should (and it is) an empty string. This is because html() look for child html.

If you write something like PyQuery('<div><script></script></div>').html() you should have <script></script> as response, but PyQuery will give you <script/>.

This is not a bug, due to help(PyQuery.html):

...
>>> d = PyQuery('<div><span></span></div>')
>>> print(d.html())
<span/>
>>> print(d.html(method='html'))
<span></span>
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants