久久久久久久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 | 99re视频这里只有精品 | 亚洲国产成人精品女人久久久 | 91精品国产综合久久久久久丝袜 | 亚洲欧美中文日韩在线v日本 | 色性av| 日韩欧美国产精品综合嫩v 一区中文字幕 | 中文字幕亚洲免费 | 操久久 | 午夜99| 亚洲成人免费观看 | 精品国产青草久久久久福利 | 国产精品第2页 | 久久久久久免费毛片精品 | 色婷婷综合久久久中字幕精品久久 | 人人九九精 | 亚洲区一区二区 | 欧美在线播放一区 | 欧美一区二区三区久久精品 | 日本一区二区高清不卡 | 久久99国产精品久久99果冻传媒 | 91九色在线观看 | 国产精品毛片一区二区在线看 | 色综合天天天天做夜夜夜夜做 | 九九久久这里只有精品 | 亚洲国产一区二区三区 | 亚洲欧美在线一区 | 波多野结衣在线观看一区二区三区 | 欧美aaa级 | 视频一区中文字幕 | 一区二区三区四区在线视频 | 日本久久www成人免 成人久久久久 | 91视频精选 | 久久免费电影 | 欧美国产激情 | 依人成人| 国精久久|