久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - 怎么查看Beautiful Soup的prettify(encoding, formatter="minimal")

瀏覽:147日期:2022-08-24 18:47:42

問(wèn)題描述

soup=bs(html)html2 = soup.prettify(’utf-8’, formatter=’minimal’)

prettify() 方法的第二個(gè)參數(shù) formatter 到底有幾個(gè)合法的取值呢?

我們只知道有 minimal, 還有什么呢?我們都不知道.怎么找到這些參數(shù)的值呢?這是 python 最不好的一個(gè)地方,方法的說(shuō)明里不寫(xiě)明白,使用者怎么尋找這些特定的取值呢?

問(wèn)題解答

回答1:

在官方的 doc 裡面就有完整的說(shuō)明了:

Output formatters

The default is formatter='minimal'. Strings will only be processed enough to ensure that Beautiful Soup generates valid HTML/XML

If you pass in formatter='html', Beautiful Soup will convert Unicode characters to HTML entities whenever possible

If you pass in formatter=None, Beautiful Soup will not modify strings at all on output. This is the fastest option, but it may lead to Beautiful Soup generating invalid HTML/XML

Finally, if you pass in a function for formatter, Beautiful Soup will call that function once for every string and attribute value in the document. You can do whatever you want in this function.

至於要找 code:

In [1]: import bs4In [2]: bs4.BeautifulSoup.prettify.__code__Out[2]: <code object prettify at 0x103f7f5d0, file '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/element.py', line 1198>

我回答過(guò)的問(wèn)題: Python-QA

回答2:

看代碼...

HTML_FORMATTERS = {'html' : HTMLAwareEntitySubstitution.substitute_html,'minimal' : HTMLAwareEntitySubstitution.substitute_xml,None : None} XML_FORMATTERS = {'html' : EntitySubstitution.substitute_html,'minimal' : EntitySubstitution.substitute_xml,None : None}

python - 怎么查看Beautiful Soup的prettify(encoding, formatter="minimal")

可以見(jiàn) https://imgur.com/gallery/VkNUv

不知道怎么顯示不出來(lái)這個(gè)圖片

標(biāo)簽: Python 編程
主站蜘蛛池模板: 郁南县| 巴楚县| 宁河县| 平乐县| 辽中县| 黄山市| 如皋市| 和硕县| 和静县| 阜平县| 漳浦县| 依安县| 英山县| 普兰县| 蓬溪县| 政和县| 昭苏县| 鄱阳县| 太湖县| 长汀县| 久治县| 舟山市| 商洛市| 聊城市| 巴中市| 繁峙县| 宝应县| 水城县| 图木舒克市| 鞍山市| 长宁区| 德化县| 五原县| 怀化市| 包头市| 安阳市| 旌德县| 丰镇市| 仁布县| 隆林| 松溪县|