python - Why does lxml.etree automatically add plus</i>?
学习ing
学习ing 2017-06-22 11:52:40
0
1
760

I am learning lxml, the code is as follows:

from lxml import etree
text = '''
<i class="cell maincell">
    <p class="title">
        <a target="_blank" href="https://itjuzi.com/company/60321">
            <span>洋鼹鼠</span>
        </a>
    </p>
    <p>
        <span class="tags t-small c-gray-aset">
            <a href="https://itjuzi.com/investevents?scope=145">电子商务</a>
        </span>
        <span class="loca c-gray-aset t-small">
            <a href="https://itjuzi.com/investevents?prov=天津">天津</a>
        </span>
    </p>
</i>
'''
html = etree.HTML(text)
print(etree.tostring(html,encoding='utf-8').decode('utf-8'))

The output is as follows:

<html><body><i class="cell maincell">
    </i><p class="title">
        <a target="_blank" href="https://itjuzi.com/company/60321">
            <span>洋鼹鼠</span>
        </a>
    </p>
    <p>
        <span class="tags t-small c-gray-aset">
            <a href="https://itjuzi.com/investevents?scope=145">电子商务</a>
        </span>
        <span class="loca c-gray-aset t-small">
            <a href="https://itjuzi.com/investevents?prov=天津">天津</a>
        </span>
    </p>

</body></html>

Mainly I don’t understand why there is an error in the <i> tag? How to solve this problem? Thank you~

学习ing
学习ing

reply all(1)
Ty80

Mainly because

p element
Content classification Flow content, palpable content.
Allowed content Phrasing content.
Allowed parent elements Any element that accepts flow content

i Element
Content catergories Flow content, phrasing content, palpable content.
Allowance phrasing content.

Obviously the parent element of the P element should be of flow content type, but i does not meet the conditions, which means it does not comply with the specification.
The solution is to replace i directly with p.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!