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

如何讓 BeautifulSoup 4 尊重自閉標簽?

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

問題描述

這個問題是針對 BeautifulSoup4 的問題,這使得它不同于以前的問題:

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

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

BeautifulSoup 中的 selfClosingTags

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

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

不會自動關閉 bar 標簽,但會給出提示.bs4 所指的這個樹生成器是什么以及如何自我關閉標簽?

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 構造函數(shù)的第二個參數(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>

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

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

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現(xiàn)問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節(jié)點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 亚洲激情在线 | 成人在线观看免费爱爱 | 视频一区在线观看 | 国产欧美一区二区三区在线看 | 色www精品视频在线观看 | 欧美色视频免费 | 亚洲国产激情 | 国产一区二区在线免费观看 | 日韩成人精品视频 | 超碰在线播| 高清亚洲 | 亚洲成在线观看 | 欧美精品一区二区三区蜜桃视频 | 毛片久久久| 国产精品日韩欧美 | 欧美13videosex性极品 | 亚洲自拍一区在线观看 | 99精品国产一区二区青青牛奶 | 免费一看一级毛片 | 综合国产在线 | 欧美激情在线一区二区三区 | 国产精品特级毛片一区二区三区 | av中文在线 | 国产精品一区二区免费看 | 91欧美精品成人综合在线观看 | 色婷婷av一区二区三区软件 | 精品视频一区二区 | 亚洲视频欧美视频 | 精品福利一区二区三区 | 久久亚洲国产精品 | 国产精品高潮呻吟久久aⅴ码 | 美女视频一区二区三区 | 久久久久久久一级 | 亚洲精品日日夜夜 | 日日夜夜天天干 | 亚洲国产精品99久久久久久久久 | 色伊人久久 | 亚洲中午字幕 | 成人av观看| 亚洲福利在线视频 | 欧美日韩成人 |