예제 #1
0
 def test_designated_empty_element_tag_does_not_change_parser_behavior(self):
     # The designated list of empty-element tags only affects how
     # empty tags are presented. It does not affect how tags are
     # parsed--that's the parser's job.
     builder = LXMLTreeBuilderForXML(empty_element_tags=['bar'])
     soup = BeautifulSoup(builder=builder, markup="<bar>contents</bar>")
     self.assertEqual(str(soup), self.document_for("<bar>contents</bar>"))
예제 #2
0
    def test_empty_tag_not_in_empty_element_tag_list_has_closing_tag(self):
        builder = LXMLTreeBuilderForXML(empty_element_tags=['bar'])

        soup = BeautifulSoup(builder=builder, markup="<foo />")
        self.assertFalse(soup.foo.is_empty_element)
        self.assertEqual(str(soup), self.document_for("<foo></foo>"))
예제 #3
0
 def default_builder(self):
     return LXMLTreeBuilderForXML()
예제 #4
0
 def test_designated_empty_element_tag_has_no_closing_tag(self):
     builder = LXMLTreeBuilderForXML(empty_element_tags=['bar'])
     soup = BeautifulSoup(builder=builder, markup="<bar></bar>")
     self.assertTrue(soup.bar.is_empty_element)
     self.assertEqual(str(soup), self.document_for("<bar />"))
예제 #5
0
파일: bs4_cdata.py 프로젝트: bhfwg/py_learn
#coding=utf8
from bs4 import CData
from bs4 import BeautifulSoup
from bs4.builder import LXMLTreeBuilderForXML

xml = \
'''
<?xml version="1.0" ?>
<foo>
    <bar><![CDATA[!@#$%^&*()_+{}|:"<>?,./;'[]\-=]]></bar>
</foo>
'''
builder = LXMLTreeBuilderForXML()
soup = BeautifulSoup(xml, "xml")
print(soup.new_string)
soup.foo.bar.string = CData(soup.foo.bar.string)
soup = soup.prettify(formatter="xml")
print(soup)