久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何讓 BeautifulSoup 4 尊重自閉標(biāo)簽?

How to get BeautifulSoup 4 to respect a self-closing tag?(如何讓 BeautifulSoup 4 尊重自閉標(biāo)簽?)
本文介紹了如何讓 BeautifulSoup 4 尊重自閉標(biāo)簽?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

這個(gè)問題是針對(duì) BeautifulSoup4 的問題,這使得它不同于以前的問題:

This question is specific to BeautifulSoup4, which makes it different from the previous questions:

BeautifulSoup 為什么要修改我的自閉合元素?

BeautifulSoup 中的 selfClosingTags

由于 BeautifulStoneSoup 已經(jīng)消失(之前的 xml 解析器),我怎樣才能讓 bs4 尊重一個(gè)新的自閉合標(biāo)簽?例如:

Since BeautifulStoneSoup is gone (the previous xml parser), how can I get bs4 to respect a new self-closing tag? For example:

import bs4   
S = '''<foo> <bar a="3"/> </foo>'''
soup = bs4.BeautifulSoup(S, selfClosingTags=['bar'])

print soup.prettify()

不會(huì)自動(dòng)關(guān)閉 bar 標(biāo)簽,但會(huì)給出提示.bs4 所指的這個(gè)樹生成器是什么以及如何自我關(guān)閉標(biāo)簽?

Does not self-close the bar tag, but gives a hint. What is this tree builder that bs4 is referring to and how to I self-close the tag?

/usr/local/lib/python2.7/dist-packages/bs4/__init__.py:112: UserWarning: BS4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.
  "BS4 does not respect the selfClosingTags argument to the "
<html>
 <body>
  <foo>
   <bar a="3">
   </bar>
  </foo>
 </body>
</html>

推薦答案

解析你傳入的XMLxml"作為 BeautifulSoup 構(gòu)造函數(shù)的第二個(gè)參數(shù).

soup = bs4.BeautifulSoup(S, 'xml')

您需要安裝 lxml.

您不再需要傳遞 selfClosingTags:

In [1]: import bs4
In [2]: S = '''<foo> <bar a="3"/> </foo>'''
In [3]: soup = bs4.BeautifulSoup(S, 'xml')
In [4]: print soup.prettify()
<?xml version="1.0" encoding="utf-8"?>
<foo>
 <bar a="3"/>
</foo>

這篇關(guān)于如何讓 BeautifulSoup 4 尊重自閉標(biāo)簽?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時(shí)出現(xiàn)問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節(jié)點(diǎn))
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應(yīng)并將元素值存儲(chǔ)在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標(biāo)記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對(duì)象)
主站蜘蛛池模板: 91视频进入 | 国产精品日韩欧美 | 一级a爱片性色毛片免费 | 精品久久久久久久久久久院品网 | 羞羞网站免费观看 | 国产精品欧美一区二区 | 亚洲乱码国产乱码精品精的特点 | 综合一区二区三区 | 精品国产乱码久久久久久丨区2区 | 欧美日韩视频 | 91久久久久久久久久久久久 | 日韩国产在线 | 久久婷婷av | 成人av一区| 日韩精品一区二区三区在线观看 | 激情小视频 | 粉嫩粉嫩芽的虎白女18在线视频 | 亚洲福利片 | 欧美男人天堂 | 热久久久久| 成人av电影天堂 | 欧洲在线视频 | 一区二区三区在线 | 日韩欧美在线视频 | 久久久久网站 | 成人性视频免费网站 | 亚洲精品一区二区三区蜜桃久 | 国产精品一区二区福利视频 | 神马久久香蕉 | 亚洲精品中文在线观看 | 亚洲一区二区三区视频免费观看 | 国产大学生情侣呻吟视频 | 九色.com| www.久久久.com | 国产网站在线免费观看 | 亚洲国产成人精品女人久久久野战 | 99视频在线免费观看 | 九九九视频在线 | 天天拍夜夜爽 | 国内在线视频 | 偷拍自拍在线观看 |