python - Warum fügt lxml.etree automatisch ein Plus</i> hinzu?
学习ing
学习ing 2017-06-22 11:52:40
0
1
728

Ich lerne lxml, der Code lautet wie folgt:

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'))

Die Ausgabe ist wie folgt:

<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>

Hauptsächlich verstehe ich nicht, warum das <i>Etikett einen Fehler enthält? Wie kann dieses Problem gelöst werden? Danke~

学习ing
学习ing

Antworte allen(1)
Ty80

主要是因为

p元素
内容分类 Flow content, palpable content.
允许的内容 Phrasing content.
允许的父元素任何接受flow content的元素

i元素
Content catergories Flow content, phrasing content, palpable content.
允许量 phrasing content.

很显然P元素的父元素应该是flow content类型的,然而i并不满足条件,也就是说这是不符合规范的。
解决办法就是i直接换为p。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!