1 <?xml version="1.0" encoding="ascii"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6 <title>lxml.html.html5parser</title>
7 <link rel="stylesheet" href="epydoc.css" type="text/css" />
8 <script type="text/javascript" src="epydoc.js"></script>
11 <body bgcolor="white" text="black" link="blue" vlink="#204080"
13 <!-- ==================== NAVIGATION BAR ==================== -->
14 <table class="navbar" border="0" width="100%" cellpadding="0"
15 bgcolor="#a0c0ff" cellspacing="0">
18 <th> <a
19 href="lxml-module.html">Home</a> </th>
22 <th> <a
23 href="module-tree.html">Trees</a> </th>
26 <th> <a
27 href="identifier-index.html">Indices</a> </th>
30 <th> <a
31 href="help.html">Help</a> </th>
33 <!-- Project homepage -->
34 <th class="navbar" align="right" width="100%">
35 <table border="0" cellpadding="0" cellspacing="0">
36 <tr><th class="navbar" align="center"
37 ><a class="navbar" target="_top" href="/">lxml API</a></th>
41 <table width="100%" cellpadding="0" cellspacing="0">
44 <span class="breadcrumbs">
45 <a href="lxml-module.html">Package lxml</a> ::
46 <a href="lxml.html-module.html">Package html</a> ::
47 Module html5parser
51 <table cellpadding="0" cellspacing="0">
52 <!-- hide/show private -->
53 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
54 onclick="toggle_private();">hide private</a>]</span></td></tr>
55 <tr><td align="right"><span class="options"
56 >[<a href="frames.html" target="_top">frames</a
57 >] | <a href="lxml.html.html5parser-pysrc.html"
58 target="_top">no frames</a>]</span></td></tr>
63 <h1 class="epydoc">Source Code for <a href="lxml.html.html5parser-module.html">Module lxml.html.html5parser</a></h1>
65 <a name="L1"></a><tt class="py-lineno"> 1</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
66 <a name="L2"></a><tt class="py-lineno"> 2</tt> <tt class="py-line"><tt class="py-docstring">An interface to html5lib that mimics the lxml.html interface.</tt> </tt>
67 <a name="L3"></a><tt class="py-lineno"> 3</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
68 <a name="L4"></a><tt class="py-lineno"> 4</tt> <tt class="py-line"> </tt>
69 <a name="L5"></a><tt class="py-lineno"> 5</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">urllib</tt> </tt>
70 <a name="L6"></a><tt class="py-lineno"> 6</tt> <tt class="py-line"> </tt>
71 <a name="L7"></a><tt class="py-lineno"> 7</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">html5lib</tt> <tt class="py-keyword">import</tt> <tt id="link-0" class="py-name" targets="Class lxml.etree.HTMLParser=lxml.etree.HTMLParser-class.html,Class lxml.html.HTMLParser=lxml.html.HTMLParser-class.html,Class lxml.html.html5parser.HTMLParser=lxml.html.html5parser.HTMLParser-class.html"><a title="lxml.etree.HTMLParser
73 lxml.html.html5parser.HTMLParser" class="py-name" href="#" onclick="return doclink('link-0', 'HTMLParser', 'link-0');">HTMLParser</a></tt> <tt class="py-keyword">as</tt> <tt class="py-name">_HTMLParser</tt> </tt>
74 <a name="L8"></a><tt class="py-lineno"> 8</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">html5lib</tt><tt class="py-op">.</tt><tt class="py-name">treebuilders</tt><tt class="py-op">.</tt><tt class="py-name">etree_lxml</tt> <tt class="py-keyword">import</tt> <tt id="link-1" class="py-name" targets="Class lxml.etree.TreeBuilder=lxml.etree.TreeBuilder-class.html,Class xml.etree.ElementTree.TreeBuilder=xml.etree.ElementTree.TreeBuilder-class.html"><a title="lxml.etree.TreeBuilder
75 xml.etree.ElementTree.TreeBuilder" class="py-name" href="#" onclick="return doclink('link-1', 'TreeBuilder', 'link-1');">TreeBuilder</a></tt> </tt>
76 <a name="L9"></a><tt class="py-lineno"> 9</tt> <tt class="py-line"> </tt>
77 <a name="L10"></a><tt class="py-lineno"> 10</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-2" class="py-name" targets="Package lxml=lxml-module.html"><a title="lxml" class="py-name" href="#" onclick="return doclink('link-2', 'lxml', 'link-2');">lxml</a></tt> <tt class="py-keyword">import</tt> <tt id="link-3" class="py-name" targets="Module lxml.etree=lxml.etree-module.html,Variable lxml.sax.ElementTreeContentHandler.etree=lxml.sax.ElementTreeContentHandler-class.html#etree,Variable lxml.tests.test_elementtree.CElementTreeTestCase.etree=lxml.tests.test_elementtree.CElementTreeTestCase-class.html#etree,Variable lxml.tests.test_elementtree.ETreeTestCaseBase.etree=lxml.tests.test_elementtree.ETreeTestCaseBase-class.html#etree,Variable lxml.tests.test_io.IOTestCaseBase.etree=lxml.tests.test_io.IOTestCaseBase-class.html#etree"><a title="lxml.etree
78 lxml.sax.ElementTreeContentHandler.etree
79 lxml.tests.test_elementtree.CElementTreeTestCase.etree
80 lxml.tests.test_elementtree.ETreeTestCaseBase.etree
81 lxml.tests.test_io.IOTestCaseBase.etree" class="py-name" href="#" onclick="return doclink('link-3', 'etree', 'link-3');">etree</a></tt> </tt>
82 <a name="L11"></a><tt class="py-lineno"> 11</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-4" class="py-name"><a title="lxml" class="py-name" href="#" onclick="return doclink('link-4', 'lxml', 'link-2');">lxml</a></tt><tt class="py-op">.</tt><tt id="link-5" class="py-name" targets="Package lxml.html=lxml.html-module.html,Method lxml.html.diff.href_token.html()=lxml.html.diff.href_token-class.html#html,Method lxml.html.diff.tag_token.html()=lxml.html.diff.tag_token-class.html#html,Method lxml.html.diff.token.html()=lxml.html.diff.token-class.html#html"><a title="lxml.html
83 lxml.html.diff.href_token.html
84 lxml.html.diff.tag_token.html
85 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-5', 'html', 'link-5');">html</a></tt> <tt class="py-keyword">import</tt> <tt id="link-6" class="py-name" targets="Function lxml.html._contains_block_level_tag()=lxml.html-module.html#_contains_block_level_tag,Function lxml.html.diff._contains_block_level_tag()=lxml.html.diff-module.html#_contains_block_level_tag"><a title="lxml.html._contains_block_level_tag
86 lxml.html.diff._contains_block_level_tag" class="py-name" href="#" onclick="return doclink('link-6', '_contains_block_level_tag', 'link-6');">_contains_block_level_tag</a></tt><tt class="py-op">,</tt> <tt id="link-7" class="py-name" targets="Variable lxml.html.XHTML_NAMESPACE=lxml.html-module.html#XHTML_NAMESPACE"><a title="lxml.html.XHTML_NAMESPACE" class="py-name" href="#" onclick="return doclink('link-7', 'XHTML_NAMESPACE', 'link-7');">XHTML_NAMESPACE</a></tt> </tt>
87 <a name="L12"></a><tt class="py-lineno"> 12</tt> <tt class="py-line"> </tt>
88 <a name="L13"></a><tt class="py-lineno"> 13</tt> <tt class="py-line"><tt class="py-comment"># python3 compatibility</tt> </tt>
89 <a name="L14"></a><tt class="py-lineno"> 14</tt> <tt class="py-line"><tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
90 <a name="L15"></a><tt class="py-lineno"> 15</tt> <tt class="py-line"> <tt class="py-name">_strings</tt> <tt class="py-op">=</tt> <tt class="py-name">basestring</tt> </tt>
91 <a name="L16"></a><tt class="py-lineno"> 16</tt> <tt class="py-line"><tt class="py-keyword">except</tt> <tt class="py-name">NameError</tt><tt class="py-op">:</tt> </tt>
92 <a name="L17"></a><tt class="py-lineno"> 17</tt> <tt class="py-line"> <tt class="py-name">_strings</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">bytes</tt><tt class="py-op">,</tt> <tt class="py-name">str</tt><tt class="py-op">)</tt> </tt>
93 <a name="L18"></a><tt class="py-lineno"> 18</tt> <tt class="py-line"> </tt>
94 <a name="L19"></a><tt class="py-lineno"> 19</tt> <tt class="py-line"> </tt>
95 <a name="HTMLParser"></a><div id="HTMLParser-def"><a name="L20"></a><tt class="py-lineno"> 20</tt> <a class="py-toggle" href="#" id="HTMLParser-toggle" onclick="return toggle('HTMLParser');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="lxml.html.html5parser.HTMLParser-class.html">HTMLParser</a><tt class="py-op">(</tt><tt class="py-base-class">_HTMLParser</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
96 </div><div id="HTMLParser-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="HTMLParser-expanded"><a name="L21"></a><tt class="py-lineno"> 21</tt> <tt class="py-line"> <tt class="py-docstring">"""An html5lib HTML parser with lxml as tree."""</tt> </tt>
97 <a name="L22"></a><tt class="py-lineno"> 22</tt> <tt class="py-line"> </tt>
98 <a name="HTMLParser.__init__"></a><div id="HTMLParser.__init__-def"><a name="L23"></a><tt class="py-lineno"> 23</tt> <a class="py-toggle" href="#" id="HTMLParser.__init__-toggle" onclick="return toggle('HTMLParser.__init__');">-</a><tt class="py-line"> <tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser.HTMLParser-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">strict</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> <tt class="py-op">**</tt><tt class="py-param">kwargs</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
99 </div><div id="HTMLParser.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="HTMLParser.__init__-expanded"><a name="L24"></a><tt class="py-lineno"> 24</tt> <tt class="py-line"> <tt class="py-name">_HTMLParser</tt><tt class="py-op">.</tt><tt id="link-8" class="py-name" targets="Method lxml.builder.ElementMaker.__init__()=lxml.builder.ElementMaker-class.html#__init__,Method lxml.cssselect.Attrib.__init__()=lxml.cssselect.Attrib-class.html#__init__,Method lxml.cssselect.CSSSelector.__init__()=lxml.cssselect.CSSSelector-class.html#__init__,Method lxml.cssselect.Class.__init__()=lxml.cssselect.Class-class.html#__init__,Method lxml.cssselect.CombinedSelector.__init__()=lxml.cssselect.CombinedSelector-class.html#__init__,Method lxml.cssselect.Element.__init__()=lxml.cssselect.Element-class.html#__init__,Method lxml.cssselect.Function.__init__()=lxml.cssselect.Function-class.html#__init__,Method lxml.cssselect.Hash.__init__()=lxml.cssselect.Hash-class.html#__init__,Method lxml.cssselect.Or.__init__()=lxml.cssselect.Or-class.html#__init__,Method lxml.cssselect.Pseudo.__init__()=lxml.cssselect.Pseudo-class.html#__init__,Method lxml.cssselect.TokenStream.__init__()=lxml.cssselect.TokenStream-class.html#__init__,Method lxml.cssselect.XPathExpr.__init__()=lxml.cssselect.XPathExpr-class.html#__init__,Method lxml.cssselect.XPathExprOr.__init__()=lxml.cssselect.XPathExprOr-class.html#__init__,Method lxml.doctestcompare._RestoreChecker.__init__()=lxml.doctestcompare._RestoreChecker-class.html#__init__,Method lxml.etree.AttributeBasedElementClassLookup.__init__()=lxml.etree.AttributeBasedElementClassLookup-class.html#__init__,Method lxml.etree.CDATA.__init__()=lxml.etree.CDATA-class.html#__init__,Method lxml.etree.CommentBase.__init__()=lxml.etree.CommentBase-class.html#__init__,Method lxml.etree.DTD.__init__()=lxml.etree.DTD-class.html#__init__,Method lxml.etree.ETCompatXMLParser.__init__()=lxml.etree.ETCompatXMLParser-class.html#__init__,Method lxml.etree.ETXPath.__init__()=lxml.etree.ETXPath-class.html#__init__,Method lxml.etree.ElementBase.__init__()=lxml.etree.ElementBase-class.html#__init__,Method lxml.etree.ElementDefaultClassLookup.__init__()=lxml.etree.ElementDefaultClassLookup-class.html#__init__,Method lxml.etree.ElementNamespaceClassLookup.__init__()=lxml.etree.ElementNamespaceClassLookup-class.html#__init__,Method lxml.etree.EntityBase.__init__()=lxml.etree.EntityBase-class.html#__init__,Method lxml.etree.FallbackElementClassLookup.__init__()=lxml.etree.FallbackElementClassLookup-class.html#__init__,Method lxml.etree.HTMLParser.__init__()=lxml.etree.HTMLParser-class.html#__init__,Method lxml.etree.LxmlError.__init__()=lxml.etree.LxmlError-class.html#__init__,Method lxml.etree.PIBase.__init__()=lxml.etree.PIBase-class.html#__init__,Method lxml.etree.ParseError.__init__()=lxml.etree.ParseError-class.html#__init__,Method lxml.etree.PyErrorLog.__init__()=lxml.etree.PyErrorLog-class.html#__init__,Method lxml.etree.QName.__init__()=lxml.etree.QName-class.html#__init__,Method lxml.etree.RelaxNG.__init__()=lxml.etree.RelaxNG-class.html#__init__,Method lxml.etree.Schematron.__init__()=lxml.etree.Schematron-class.html#__init__,Method lxml.etree.TreeBuilder.__init__()=lxml.etree.TreeBuilder-class.html#__init__,Method lxml.etree.XInclude.__init__()=lxml.etree.XInclude-class.html#__init__,Method lxml.etree.XMLParser.__init__()=lxml.etree.XMLParser-class.html#__init__,Method lxml.etree.XMLSchema.__init__()=lxml.etree.XMLSchema-class.html#__init__,Method lxml.etree.XPath.__init__()=lxml.etree.XPath-class.html#__init__,Method lxml.etree.XPathDocumentEvaluator.__init__()=lxml.etree.XPathDocumentEvaluator-class.html#__init__,Method lxml.etree.XPathElementEvaluator.__init__()=lxml.etree.XPathElementEvaluator-class.html#__init__,Method lxml.etree.XSLT.__init__()=lxml.etree.XSLT-class.html#__init__,Method lxml.etree._BaseContext.__init__()=lxml.etree._BaseContext-class.html#__init__,Method lxml.etree._BaseErrorLog.__init__()=lxml.etree._BaseErrorLog-class.html#__init__,Method lxml.etree._BaseParser.__init__()=lxml.etree._BaseParser-class.html#__init__,Method lxml.etree._DomainErrorLog.__init__()=lxml.etree._DomainErrorLog-class.html#__init__,Method lxml.etree._ErrorLog.__init__()=lxml.etree._ErrorLog-class.html#__init__,Method lxml.etree._ListErrorLog.__init__()=lxml.etree._ListErrorLog-class.html#__init__,Method lxml.etree._OpaqueNodeWrapper.__init__()=lxml.etree._OpaqueNodeWrapper-class.html#__init__,Method lxml.etree._RotatingErrorLog.__init__()=lxml.etree._RotatingErrorLog-class.html#__init__,Method lxml.etree._TargetParserResult.__init__()=lxml.etree._TargetParserResult-class.html#__init__,Method lxml.etree._TempStore.__init__()=lxml.etree._TempStore-class.html#__init__,Method lxml.etree._XPathContext.__init__()=lxml.etree._XPathContext-class.html#__init__,Method lxml.etree._XPathEvaluatorBase.__init__()=lxml.etree._XPathEvaluatorBase-class.html#__init__,Method lxml.etree._XSLTContext.__init__()=lxml.etree._XSLTContext-class.html#__init__,Method lxml.etree.iterparse.__init__()=lxml.etree.iterparse-class.html#__init__,Method lxml.etree.iterwalk.__init__()=lxml.etree.iterwalk-class.html#__init__,Method lxml.html.CheckboxValues.__init__()=lxml.html.CheckboxValues-class.html#__init__,Method lxml.html.FieldsDict.__init__()=lxml.html.FieldsDict-class.html#__init__,Method lxml.html.HTMLParser.__init__()=lxml.html.HTMLParser-class.html#__init__,Method lxml.html.HtmlElementClassLookup.__init__()=lxml.html.HtmlElementClassLookup-class.html#__init__,Method lxml.html.InputGetter.__init__()=lxml.html.InputGetter-class.html#__init__,Method lxml.html.MultipleSelectOptions.__init__()=lxml.html.MultipleSelectOptions-class.html#__init__,Method lxml.html.XHTMLParser.__init__()=lxml.html.XHTMLParser-class.html#__init__,Method lxml.html._MethodFunc.__init__()=lxml.html._MethodFunc-class.html#__init__,Method lxml.html.clean.Cleaner.__init__()=lxml.html.clean.Cleaner-class.html#__init__,Method lxml.html.formfill.DefaultErrorCreator.__init__()=lxml.html.formfill.DefaultErrorCreator-class.html#__init__,Method lxml.html.html5parser.HTMLParser.__init__()=lxml.html.html5parser.HTMLParser-class.html#__init__,Method lxml.html.html5parser.XHTMLParser.__init__()=lxml.html.html5parser.XHTMLParser-class.html#__init__,Method lxml.isoschematron.Schematron.__init__()=lxml.isoschematron.Schematron-class.html#__init__,Method lxml.objectify.ElementMaker.__init__()=lxml.objectify.ElementMaker-class.html#__init__,Method lxml.objectify.ObjectPath.__init__()=lxml.objectify.ObjectPath-class.html#__init__,Method lxml.objectify.ObjectifyElementClassLookup.__init__()=lxml.objectify.ObjectifyElementClassLookup-class.html#__init__,Method lxml.objectify.PyType.__init__()=lxml.objectify.PyType-class.html#__init__,Method lxml.sax.ElementTreeContentHandler.__init__()=lxml.sax.ElementTreeContentHandler-class.html#__init__,Method lxml.sax.ElementTreeProducer.__init__()=lxml.sax.ElementTreeProducer-class.html#__init__,Method lxml.tests.common_imports.LargeFileLike.__init__()=lxml.tests.common_imports.LargeFileLike-class.html#__init__,Method lxml.tests.common_imports.LargeFileLikeUnicode.__init__()=lxml.tests.common_imports.LargeFileLikeUnicode-class.html#__init__,Method lxml.tests.common_imports.SillyFileLike.__init__()=lxml.tests.common_imports.SillyFileLike-class.html#__init__,Method lxml.tests.test_css.CSSTestCase.__init__()=lxml.tests.test_css.CSSTestCase-class.html#__init__,Method lxml.tests.test_threading.ThreadPipelineTestCase.Worker.__init__()=lxml.tests.test_threading.ThreadPipelineTestCase.Worker-class.html#__init__,Method lxml.tests.test_xmlschema.ETreeXMLSchemaResolversTestCase.simple_resolver.__init__()=lxml.tests.test_xmlschema.ETreeXMLSchemaResolversTestCase.simple_resolver-class.html#__init__"><a title="lxml.builder.ElementMaker.__init__
100 lxml.cssselect.Attrib.__init__
101 lxml.cssselect.CSSSelector.__init__
102 lxml.cssselect.Class.__init__
103 lxml.cssselect.CombinedSelector.__init__
104 lxml.cssselect.Element.__init__
105 lxml.cssselect.Function.__init__
106 lxml.cssselect.Hash.__init__
107 lxml.cssselect.Or.__init__
108 lxml.cssselect.Pseudo.__init__
109 lxml.cssselect.TokenStream.__init__
110 lxml.cssselect.XPathExpr.__init__
111 lxml.cssselect.XPathExprOr.__init__
112 lxml.doctestcompare._RestoreChecker.__init__
113 lxml.etree.AttributeBasedElementClassLookup.__init__
114 lxml.etree.CDATA.__init__
115 lxml.etree.CommentBase.__init__
116 lxml.etree.DTD.__init__
117 lxml.etree.ETCompatXMLParser.__init__
118 lxml.etree.ETXPath.__init__
119 lxml.etree.ElementBase.__init__
120 lxml.etree.ElementDefaultClassLookup.__init__
121 lxml.etree.ElementNamespaceClassLookup.__init__
122 lxml.etree.EntityBase.__init__
123 lxml.etree.FallbackElementClassLookup.__init__
124 lxml.etree.HTMLParser.__init__
125 lxml.etree.LxmlError.__init__
126 lxml.etree.PIBase.__init__
127 lxml.etree.ParseError.__init__
128 lxml.etree.PyErrorLog.__init__
129 lxml.etree.QName.__init__
130 lxml.etree.RelaxNG.__init__
131 lxml.etree.Schematron.__init__
132 lxml.etree.TreeBuilder.__init__
133 lxml.etree.XInclude.__init__
134 lxml.etree.XMLParser.__init__
135 lxml.etree.XMLSchema.__init__
136 lxml.etree.XPath.__init__
137 lxml.etree.XPathDocumentEvaluator.__init__
138 lxml.etree.XPathElementEvaluator.__init__
139 lxml.etree.XSLT.__init__
140 lxml.etree._BaseContext.__init__
141 lxml.etree._BaseErrorLog.__init__
142 lxml.etree._BaseParser.__init__
143 lxml.etree._DomainErrorLog.__init__
144 lxml.etree._ErrorLog.__init__
145 lxml.etree._ListErrorLog.__init__
146 lxml.etree._OpaqueNodeWrapper.__init__
147 lxml.etree._RotatingErrorLog.__init__
148 lxml.etree._TargetParserResult.__init__
149 lxml.etree._TempStore.__init__
150 lxml.etree._XPathContext.__init__
151 lxml.etree._XPathEvaluatorBase.__init__
152 lxml.etree._XSLTContext.__init__
153 lxml.etree.iterparse.__init__
154 lxml.etree.iterwalk.__init__
155 lxml.html.CheckboxValues.__init__
156 lxml.html.FieldsDict.__init__
157 lxml.html.HTMLParser.__init__
158 lxml.html.HtmlElementClassLookup.__init__
159 lxml.html.InputGetter.__init__
160 lxml.html.MultipleSelectOptions.__init__
161 lxml.html.XHTMLParser.__init__
162 lxml.html._MethodFunc.__init__
163 lxml.html.clean.Cleaner.__init__
164 lxml.html.formfill.DefaultErrorCreator.__init__
165 lxml.html.html5parser.HTMLParser.__init__
166 lxml.html.html5parser.XHTMLParser.__init__
167 lxml.isoschematron.Schematron.__init__
168 lxml.objectify.ElementMaker.__init__
169 lxml.objectify.ObjectPath.__init__
170 lxml.objectify.ObjectifyElementClassLookup.__init__
171 lxml.objectify.PyType.__init__
172 lxml.sax.ElementTreeContentHandler.__init__
173 lxml.sax.ElementTreeProducer.__init__
174 lxml.tests.common_imports.LargeFileLike.__init__
175 lxml.tests.common_imports.LargeFileLikeUnicode.__init__
176 lxml.tests.common_imports.SillyFileLike.__init__
177 lxml.tests.test_css.CSSTestCase.__init__
178 lxml.tests.test_threading.ThreadPipelineTestCase.Worker.__init__
179 lxml.tests.test_xmlschema.ETreeXMLSchemaResolversTestCase.simple_resolver.__init__" class="py-name" href="#" onclick="return doclink('link-8', '__init__', 'link-8');">__init__</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">,</tt> <tt class="py-name">strict</tt><tt class="py-op">=</tt><tt class="py-name">strict</tt><tt class="py-op">,</tt> <tt class="py-name">tree</tt><tt class="py-op">=</tt><tt id="link-9" class="py-name"><a title="lxml.etree.TreeBuilder
180 xml.etree.ElementTree.TreeBuilder" class="py-name" href="#" onclick="return doclink('link-9', 'TreeBuilder', 'link-1');">TreeBuilder</a></tt><tt class="py-op">,</tt> <tt class="py-op">**</tt><tt class="py-name">kwargs</tt><tt class="py-op">)</tt> </tt>
181 </div></div><a name="L25"></a><tt class="py-lineno"> 25</tt> <tt class="py-line"> </tt>
182 <a name="L26"></a><tt class="py-lineno"> 26</tt> <tt class="py-line"> </tt>
183 <a name="L27"></a><tt class="py-lineno"> 27</tt> <tt class="py-line"><tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
184 <a name="L28"></a><tt class="py-lineno"> 28</tt> <tt class="py-line"> <tt class="py-keyword">from</tt> <tt class="py-name">html5lib</tt> <tt class="py-keyword">import</tt> <tt id="link-10" class="py-name" targets="Class lxml.html.XHTMLParser=lxml.html.XHTMLParser-class.html,Class lxml.html.html5parser.XHTMLParser=lxml.html.html5parser.XHTMLParser-class.html"><a title="lxml.html.XHTMLParser
185 lxml.html.html5parser.XHTMLParser" class="py-name" href="#" onclick="return doclink('link-10', 'XHTMLParser', 'link-10');">XHTMLParser</a></tt> <tt class="py-keyword">as</tt> <tt class="py-name">_XHTMLParser</tt> </tt>
186 <a name="L29"></a><tt class="py-lineno"> 29</tt> <tt class="py-line"><tt class="py-keyword">except</tt> <tt class="py-name">ImportError</tt><tt class="py-op">:</tt> </tt>
187 <a name="L30"></a><tt class="py-lineno"> 30</tt> <tt class="py-line"> <tt class="py-keyword">pass</tt> </tt>
188 <a name="L31"></a><tt class="py-lineno"> 31</tt> <tt class="py-line"><tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
189 <a name="XHTMLParser"></a><div id="XHTMLParser-def"><a name="L32"></a><tt class="py-lineno"> 32</tt> <a class="py-toggle" href="#" id="XHTMLParser-toggle" onclick="return toggle('XHTMLParser');">-</a><tt class="py-line"> <tt class="py-keyword">class</tt> <a class="py-def-name" href="lxml.html.html5parser.XHTMLParser-class.html">XHTMLParser</a><tt class="py-op">(</tt><tt class="py-base-class">_XHTMLParser</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
190 </div><div id="XHTMLParser-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="XHTMLParser-expanded"><a name="L33"></a><tt class="py-lineno"> 33</tt> <tt class="py-line"> <tt class="py-docstring">"""An html5lib XHTML Parser with lxml as tree."""</tt> </tt>
191 <a name="L34"></a><tt class="py-lineno"> 34</tt> <tt class="py-line"> </tt>
192 <a name="XHTMLParser.__init__"></a><div id="XHTMLParser.__init__-def"><a name="L35"></a><tt class="py-lineno"> 35</tt> <a class="py-toggle" href="#" id="XHTMLParser.__init__-toggle" onclick="return toggle('XHTMLParser.__init__');">-</a><tt class="py-line"> <tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser.XHTMLParser-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">strict</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> <tt class="py-op">**</tt><tt class="py-param">kwargs</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
193 </div><div id="XHTMLParser.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++++++++++"></div><div id="XHTMLParser.__init__-expanded"><a name="L36"></a><tt class="py-lineno"> 36</tt> <tt class="py-line"> <tt class="py-name">_XHTMLParser</tt><tt class="py-op">.</tt><tt id="link-11" class="py-name"><a title="lxml.builder.ElementMaker.__init__
194 lxml.cssselect.Attrib.__init__
195 lxml.cssselect.CSSSelector.__init__
196 lxml.cssselect.Class.__init__
197 lxml.cssselect.CombinedSelector.__init__
198 lxml.cssselect.Element.__init__
199 lxml.cssselect.Function.__init__
200 lxml.cssselect.Hash.__init__
201 lxml.cssselect.Or.__init__
202 lxml.cssselect.Pseudo.__init__
203 lxml.cssselect.TokenStream.__init__
204 lxml.cssselect.XPathExpr.__init__
205 lxml.cssselect.XPathExprOr.__init__
206 lxml.doctestcompare._RestoreChecker.__init__
207 lxml.etree.AttributeBasedElementClassLookup.__init__
208 lxml.etree.CDATA.__init__
209 lxml.etree.CommentBase.__init__
210 lxml.etree.DTD.__init__
211 lxml.etree.ETCompatXMLParser.__init__
212 lxml.etree.ETXPath.__init__
213 lxml.etree.ElementBase.__init__
214 lxml.etree.ElementDefaultClassLookup.__init__
215 lxml.etree.ElementNamespaceClassLookup.__init__
216 lxml.etree.EntityBase.__init__
217 lxml.etree.FallbackElementClassLookup.__init__
218 lxml.etree.HTMLParser.__init__
219 lxml.etree.LxmlError.__init__
220 lxml.etree.PIBase.__init__
221 lxml.etree.ParseError.__init__
222 lxml.etree.PyErrorLog.__init__
223 lxml.etree.QName.__init__
224 lxml.etree.RelaxNG.__init__
225 lxml.etree.Schematron.__init__
226 lxml.etree.TreeBuilder.__init__
227 lxml.etree.XInclude.__init__
228 lxml.etree.XMLParser.__init__
229 lxml.etree.XMLSchema.__init__
230 lxml.etree.XPath.__init__
231 lxml.etree.XPathDocumentEvaluator.__init__
232 lxml.etree.XPathElementEvaluator.__init__
233 lxml.etree.XSLT.__init__
234 lxml.etree._BaseContext.__init__
235 lxml.etree._BaseErrorLog.__init__
236 lxml.etree._BaseParser.__init__
237 lxml.etree._DomainErrorLog.__init__
238 lxml.etree._ErrorLog.__init__
239 lxml.etree._ListErrorLog.__init__
240 lxml.etree._OpaqueNodeWrapper.__init__
241 lxml.etree._RotatingErrorLog.__init__
242 lxml.etree._TargetParserResult.__init__
243 lxml.etree._TempStore.__init__
244 lxml.etree._XPathContext.__init__
245 lxml.etree._XPathEvaluatorBase.__init__
246 lxml.etree._XSLTContext.__init__
247 lxml.etree.iterparse.__init__
248 lxml.etree.iterwalk.__init__
249 lxml.html.CheckboxValues.__init__
250 lxml.html.FieldsDict.__init__
251 lxml.html.HTMLParser.__init__
252 lxml.html.HtmlElementClassLookup.__init__
253 lxml.html.InputGetter.__init__
254 lxml.html.MultipleSelectOptions.__init__
255 lxml.html.XHTMLParser.__init__
256 lxml.html._MethodFunc.__init__
257 lxml.html.clean.Cleaner.__init__
258 lxml.html.formfill.DefaultErrorCreator.__init__
259 lxml.html.html5parser.HTMLParser.__init__
260 lxml.html.html5parser.XHTMLParser.__init__
261 lxml.isoschematron.Schematron.__init__
262 lxml.objectify.ElementMaker.__init__
263 lxml.objectify.ObjectPath.__init__
264 lxml.objectify.ObjectifyElementClassLookup.__init__
265 lxml.objectify.PyType.__init__
266 lxml.sax.ElementTreeContentHandler.__init__
267 lxml.sax.ElementTreeProducer.__init__
268 lxml.tests.common_imports.LargeFileLike.__init__
269 lxml.tests.common_imports.LargeFileLikeUnicode.__init__
270 lxml.tests.common_imports.SillyFileLike.__init__
271 lxml.tests.test_css.CSSTestCase.__init__
272 lxml.tests.test_threading.ThreadPipelineTestCase.Worker.__init__
273 lxml.tests.test_xmlschema.ETreeXMLSchemaResolversTestCase.simple_resolver.__init__" class="py-name" href="#" onclick="return doclink('link-11', '__init__', 'link-8');">__init__</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">,</tt> <tt class="py-name">strict</tt><tt class="py-op">=</tt><tt class="py-name">strict</tt><tt class="py-op">,</tt> <tt class="py-name">tree</tt><tt class="py-op">=</tt><tt id="link-12" class="py-name"><a title="lxml.etree.TreeBuilder
274 xml.etree.ElementTree.TreeBuilder" class="py-name" href="#" onclick="return doclink('link-12', 'TreeBuilder', 'link-1');">TreeBuilder</a></tt><tt class="py-op">,</tt> <tt class="py-op">**</tt><tt class="py-name">kwargs</tt><tt class="py-op">)</tt> </tt>
275 </div></div><a name="L37"></a><tt class="py-lineno"> 37</tt> <tt class="py-line"> </tt>
276 <a name="L38"></a><tt class="py-lineno"> 38</tt> <tt class="py-line"> <tt id="link-13" class="py-name" targets="Variable lxml.html.html5parser.xhtml_parser=lxml.html.html5parser-module.html#xhtml_parser,Variable lxml.html.xhtml_parser=lxml.html-module.html#xhtml_parser"><a title="lxml.html.html5parser.xhtml_parser
277 lxml.html.xhtml_parser" class="py-name" href="#" onclick="return doclink('link-13', 'xhtml_parser', 'link-13');">xhtml_parser</a></tt> <tt class="py-op">=</tt> <tt id="link-14" class="py-name"><a title="lxml.html.XHTMLParser
278 lxml.html.html5parser.XHTMLParser" class="py-name" href="#" onclick="return doclink('link-14', 'XHTMLParser', 'link-10');">XHTMLParser</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
279 <a name="L39"></a><tt class="py-lineno"> 39</tt> <tt class="py-line"> </tt>
280 <a name="L40"></a><tt class="py-lineno"> 40</tt> <tt class="py-line"> </tt>
281 <a name="_find_tag"></a><div id="_find_tag-def"><a name="L41"></a><tt class="py-lineno"> 41</tt> <a class="py-toggle" href="#" id="_find_tag-toggle" onclick="return toggle('_find_tag');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#_find_tag">_find_tag</a><tt class="py-op">(</tt><tt class="py-param">tree</tt><tt class="py-op">,</tt> <tt class="py-param">tag</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
282 </div><div id="_find_tag-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="_find_tag-expanded"><a name="L42"></a><tt class="py-lineno"> 42</tt> <tt class="py-line"> <tt class="py-name">elem</tt> <tt class="py-op">=</tt> <tt class="py-name">tree</tt><tt class="py-op">.</tt><tt id="link-15" class="py-name" targets="Method lxml.etree._Element.find()=lxml.etree._Element-class.html#find,Method lxml.etree._ElementTree.find()=lxml.etree._ElementTree-class.html#find,Variable lxml.objectify.ObjectPath.find=lxml.objectify.ObjectPath-class.html#find,Method lxml.objectify.ObjectifiedElement.find()=lxml.objectify.ObjectifiedElement-class.html#find"><a title="lxml.etree._Element.find
283 lxml.etree._ElementTree.find
284 lxml.objectify.ObjectPath.find
285 lxml.objectify.ObjectifiedElement.find" class="py-name" href="#" onclick="return doclink('link-15', 'find', 'link-15');">find</a></tt><tt class="py-op">(</tt><tt id="link-16" class="py-name" targets="Variable lxml.etree._Comment.tag=lxml.etree._Comment-class.html#tag,Variable lxml.etree._Element.tag=lxml.etree._Element-class.html#tag,Variable lxml.etree._Entity.tag=lxml.etree._Entity-class.html#tag,Variable lxml.etree._ProcessingInstruction.tag=lxml.etree._ProcessingInstruction-class.html#tag,Variable lxml.etree._ReadOnlyProxy.tag=lxml.etree._ReadOnlyProxy-class.html#tag,Function lxml.tests.test_xpathevaluator.tag()=lxml.tests.test_xpathevaluator-module.html#tag,Variable xml.etree.ElementTree.Element.tag=xml.etree.ElementTree.Element-class.html#tag"><a title="lxml.etree._Comment.tag
286 lxml.etree._Element.tag
287 lxml.etree._Entity.tag
288 lxml.etree._ProcessingInstruction.tag
289 lxml.etree._ReadOnlyProxy.tag
290 lxml.tests.test_xpathevaluator.tag
291 xml.etree.ElementTree.Element.tag" class="py-name" href="#" onclick="return doclink('link-16', 'tag', 'link-16');">tag</a></tt><tt class="py-op">)</tt> </tt>
292 <a name="L43"></a><tt class="py-lineno"> 43</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">elem</tt> <tt class="py-keyword">is</tt> <tt class="py-keyword">not</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
293 <a name="L44"></a><tt class="py-lineno"> 44</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">elem</tt> </tt>
294 <a name="L45"></a><tt class="py-lineno"> 45</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">tree</tt><tt class="py-op">.</tt><tt id="link-17" class="py-name"><a title="lxml.etree._Element.find
295 lxml.etree._ElementTree.find
296 lxml.objectify.ObjectPath.find
297 lxml.objectify.ObjectifiedElement.find" class="py-name" href="#" onclick="return doclink('link-17', 'find', 'link-15');">find</a></tt><tt class="py-op">(</tt><tt class="py-string">'{%s}%s'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt id="link-18" class="py-name"><a title="lxml.html.XHTML_NAMESPACE" class="py-name" href="#" onclick="return doclink('link-18', 'XHTML_NAMESPACE', 'link-7');">XHTML_NAMESPACE</a></tt><tt class="py-op">,</tt> <tt id="link-19" class="py-name"><a title="lxml.etree._Comment.tag
298 lxml.etree._Element.tag
299 lxml.etree._Entity.tag
300 lxml.etree._ProcessingInstruction.tag
301 lxml.etree._ReadOnlyProxy.tag
302 lxml.tests.test_xpathevaluator.tag
303 xml.etree.ElementTree.Element.tag" class="py-name" href="#" onclick="return doclink('link-19', 'tag', 'link-16');">tag</a></tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
304 </div><a name="L46"></a><tt class="py-lineno"> 46</tt> <tt class="py-line"> </tt>
305 <a name="L47"></a><tt class="py-lineno"> 47</tt> <tt class="py-line"> </tt>
306 <a name="document_fromstring"></a><div id="document_fromstring-def"><a name="L48"></a><tt class="py-lineno"> 48</tt> <a class="py-toggle" href="#" id="document_fromstring-toggle" onclick="return toggle('document_fromstring');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#document_fromstring">document_fromstring</a><tt class="py-op">(</tt><tt class="py-param">html</tt><tt class="py-op">,</tt> <tt class="py-param">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">,</tt> <tt class="py-param">parser</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
307 </div><div id="document_fromstring-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="document_fromstring-expanded"><a name="L49"></a><tt class="py-lineno"> 49</tt> <tt class="py-line"> <tt class="py-docstring">"""Parse a whole document into a string."""</tt> </tt>
308 <a name="L50"></a><tt class="py-lineno"> 50</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt id="link-20" class="py-name"><a title="lxml.html
309 lxml.html.diff.href_token.html
310 lxml.html.diff.tag_token.html
311 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-20', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">_strings</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
312 <a name="L51"></a><tt class="py-lineno"> 51</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt class="py-name">TypeError</tt><tt class="py-op">(</tt><tt class="py-string">'string required'</tt><tt class="py-op">)</tt> </tt>
313 <a name="L52"></a><tt class="py-lineno"> 52</tt> <tt class="py-line"> </tt>
314 <a name="L53"></a><tt class="py-lineno"> 53</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-21" class="py-name" targets="Variable lxml.etree._ElementTree.parser=lxml.etree._ElementTree-class.html#parser,Variable lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser=lxml.tests.test_pyclasslookup.PyClassLookupTestCase-class.html#parser"><a title="lxml.etree._ElementTree.parser
315 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-21', 'parser', 'link-21');">parser</a></tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
316 <a name="L54"></a><tt class="py-lineno"> 54</tt> <tt class="py-line"> <tt id="link-22" class="py-name"><a title="lxml.etree._ElementTree.parser
317 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-22', 'parser', 'link-21');">parser</a></tt> <tt class="py-op">=</tt> <tt id="link-23" class="py-name" targets="Variable lxml.html.html5parser.html_parser=lxml.html.html5parser-module.html#html_parser,Variable lxml.html.html_parser=lxml.html-module.html#html_parser"><a title="lxml.html.html5parser.html_parser
318 lxml.html.html_parser" class="py-name" href="#" onclick="return doclink('link-23', 'html_parser', 'link-23');">html_parser</a></tt> </tt>
319 <a name="L55"></a><tt class="py-lineno"> 55</tt> <tt class="py-line"> </tt>
320 <a name="L56"></a><tt class="py-lineno"> 56</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-24" class="py-name"><a title="lxml.etree._ElementTree.parser
321 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-24', 'parser', 'link-21');">parser</a></tt><tt class="py-op">.</tt><tt id="link-25" class="py-name" targets="Function lxml.cssselect.parse()=lxml.cssselect-module.html#parse,Method lxml.etree._ElementTree.parse()=lxml.etree._ElementTree-class.html#parse,Function lxml.etree.parse()=lxml.etree-module.html#parse,Function lxml.html.ElementSoup.parse()=lxml.html.ElementSoup-module.html#parse,Function lxml.html.html5parser.parse()=lxml.html.html5parser-module.html#parse,Function lxml.html.parse()=lxml.html-module.html#parse,Function lxml.html.soupparser.parse()=lxml.html.soupparser-module.html#parse,Function lxml.objectify.parse()=lxml.objectify-module.html#parse,Method lxml.tests.common_imports.HelperTestCase.parse()=lxml.tests.common_imports.HelperTestCase-class.html#parse"><a title="lxml.cssselect.parse
322 lxml.etree._ElementTree.parse
324 lxml.html.ElementSoup.parse
325 lxml.html.html5parser.parse
327 lxml.html.soupparser.parse
329 lxml.tests.common_imports.HelperTestCase.parse" class="py-name" href="#" onclick="return doclink('link-25', 'parse', 'link-25');">parse</a></tt><tt class="py-op">(</tt><tt id="link-26" class="py-name"><a title="lxml.html
330 lxml.html.diff.href_token.html
331 lxml.html.diff.tag_token.html
332 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-26', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">useChardet</tt><tt class="py-op">=</tt><tt class="py-name">guess_charset</tt><tt class="py-op">)</tt><tt class="py-op">.</tt><tt id="link-27" class="py-name" targets="Method lxml.etree._ElementTree.getroot()=lxml.etree._ElementTree-class.html#getroot"><a title="lxml.etree._ElementTree.getroot" class="py-name" href="#" onclick="return doclink('link-27', 'getroot', 'link-27');">getroot</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
333 </div><a name="L57"></a><tt class="py-lineno"> 57</tt> <tt class="py-line"> </tt>
334 <a name="L58"></a><tt class="py-lineno"> 58</tt> <tt class="py-line"> </tt>
335 <a name="fragments_fromstring"></a><div id="fragments_fromstring-def"><a name="L59"></a><tt class="py-lineno"> 59</tt> <a class="py-toggle" href="#" id="fragments_fromstring-toggle" onclick="return toggle('fragments_fromstring');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#fragments_fromstring">fragments_fromstring</a><tt class="py-op">(</tt><tt class="py-param">html</tt><tt class="py-op">,</tt> <tt class="py-param">no_leading_text</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> </tt>
336 <a name="L60"></a><tt class="py-lineno"> 60</tt> <tt class="py-line"> <tt class="py-param">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> <tt class="py-param">parser</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
337 </div><div id="fragments_fromstring-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="fragments_fromstring-expanded"><a name="L61"></a><tt class="py-lineno"> 61</tt> <tt class="py-line"> <tt class="py-docstring">"""Parses several HTML elements, returning a list of elements.</tt> </tt>
338 <a name="L62"></a><tt class="py-lineno"> 62</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
339 <a name="L63"></a><tt class="py-lineno"> 63</tt> <tt class="py-line"><tt class="py-docstring"> The first item in the list may be a string. If no_leading_text is true,</tt> </tt>
340 <a name="L64"></a><tt class="py-lineno"> 64</tt> <tt class="py-line"><tt class="py-docstring"> then it will be an error if there is leading text, and it will always be</tt> </tt>
341 <a name="L65"></a><tt class="py-lineno"> 65</tt> <tt class="py-line"><tt class="py-docstring"> a list of only elements.</tt> </tt>
342 <a name="L66"></a><tt class="py-lineno"> 66</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
343 <a name="L67"></a><tt class="py-lineno"> 67</tt> <tt class="py-line"><tt class="py-docstring"> If `guess_charset` is `True` and the text was not unicode but a</tt> </tt>
344 <a name="L68"></a><tt class="py-lineno"> 68</tt> <tt class="py-line"><tt class="py-docstring"> bytestring, the `chardet` library will perform charset guessing on the</tt> </tt>
345 <a name="L69"></a><tt class="py-lineno"> 69</tt> <tt class="py-line"><tt class="py-docstring"> string.</tt> </tt>
346 <a name="L70"></a><tt class="py-lineno"> 70</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
347 <a name="L71"></a><tt class="py-lineno"> 71</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt id="link-28" class="py-name"><a title="lxml.html
348 lxml.html.diff.href_token.html
349 lxml.html.diff.tag_token.html
350 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-28', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">_strings</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
351 <a name="L72"></a><tt class="py-lineno"> 72</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt class="py-name">TypeError</tt><tt class="py-op">(</tt><tt class="py-string">'string required'</tt><tt class="py-op">)</tt> </tt>
352 <a name="L73"></a><tt class="py-lineno"> 73</tt> <tt class="py-line"> </tt>
353 <a name="L74"></a><tt class="py-lineno"> 74</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-29" class="py-name"><a title="lxml.etree._ElementTree.parser
354 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-29', 'parser', 'link-21');">parser</a></tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
355 <a name="L75"></a><tt class="py-lineno"> 75</tt> <tt class="py-line"> <tt id="link-30" class="py-name"><a title="lxml.etree._ElementTree.parser
356 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-30', 'parser', 'link-21');">parser</a></tt> <tt class="py-op">=</tt> <tt id="link-31" class="py-name"><a title="lxml.html.html5parser.html_parser
357 lxml.html.html_parser" class="py-name" href="#" onclick="return doclink('link-31', 'html_parser', 'link-23');">html_parser</a></tt> </tt>
358 <a name="L76"></a><tt class="py-lineno"> 76</tt> <tt class="py-line"> </tt>
359 <a name="L77"></a><tt class="py-lineno"> 77</tt> <tt class="py-line"> <tt class="py-name">children</tt> <tt class="py-op">=</tt> <tt id="link-32" class="py-name"><a title="lxml.etree._ElementTree.parser
360 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-32', 'parser', 'link-21');">parser</a></tt><tt class="py-op">.</tt><tt class="py-name">parseFragment</tt><tt class="py-op">(</tt><tt id="link-33" class="py-name"><a title="lxml.html
361 lxml.html.diff.href_token.html
362 lxml.html.diff.tag_token.html
363 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-33', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-string">'div'</tt><tt class="py-op">,</tt> <tt class="py-name">useChardet</tt><tt class="py-op">=</tt><tt class="py-name">guess_charset</tt><tt class="py-op">)</tt> </tt>
364 <a name="L78"></a><tt class="py-lineno"> 78</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">children</tt> <tt class="py-keyword">and</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">children</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">,</tt> <tt class="py-name">_strings</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
365 <a name="L79"></a><tt class="py-lineno"> 79</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">no_leading_text</tt><tt class="py-op">:</tt> </tt>
366 <a name="L80"></a><tt class="py-lineno"> 80</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">children</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">.</tt><tt id="link-34" class="py-name" targets="Function lxml.doctestcompare.strip()=lxml.doctestcompare-module.html#strip"><a title="lxml.doctestcompare.strip" class="py-name" href="#" onclick="return doclink('link-34', 'strip', 'link-34');">strip</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
367 <a name="L81"></a><tt class="py-lineno"> 81</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt id="link-35" class="py-name"><a title="lxml.etree
368 lxml.sax.ElementTreeContentHandler.etree
369 lxml.tests.test_elementtree.CElementTreeTestCase.etree
370 lxml.tests.test_elementtree.ETreeTestCaseBase.etree
371 lxml.tests.test_io.IOTestCaseBase.etree" class="py-name" href="#" onclick="return doclink('link-35', 'etree', 'link-3');">etree</a></tt><tt class="py-op">.</tt><tt id="link-36" class="py-name" targets="Class lxml.etree.ParserError=lxml.etree.ParserError-class.html"><a title="lxml.etree.ParserError" class="py-name" href="#" onclick="return doclink('link-36', 'ParserError', 'link-36');">ParserError</a></tt><tt class="py-op">(</tt><tt class="py-string">'There is leading text: %r'</tt> <tt class="py-op">%</tt> </tt>
372 <a name="L82"></a><tt class="py-lineno"> 82</tt> <tt class="py-line"> <tt class="py-name">children</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
373 <a name="L83"></a><tt class="py-lineno"> 83</tt> <tt class="py-line"> <tt class="py-keyword">del</tt> <tt class="py-name">children</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> </tt>
374 <a name="L84"></a><tt class="py-lineno"> 84</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">children</tt> </tt>
375 </div><a name="L85"></a><tt class="py-lineno"> 85</tt> <tt class="py-line"> </tt>
376 <a name="L86"></a><tt class="py-lineno"> 86</tt> <tt class="py-line"> </tt>
377 <a name="fragment_fromstring"></a><div id="fragment_fromstring-def"><a name="L87"></a><tt class="py-lineno"> 87</tt> <a class="py-toggle" href="#" id="fragment_fromstring-toggle" onclick="return toggle('fragment_fromstring');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#fragment_fromstring">fragment_fromstring</a><tt class="py-op">(</tt><tt class="py-param">html</tt><tt class="py-op">,</tt> <tt class="py-param">create_parent</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> </tt>
378 <a name="L88"></a><tt class="py-lineno"> 88</tt> <tt class="py-line"> <tt class="py-param">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> <tt class="py-param">parser</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
379 </div><div id="fragment_fromstring-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="fragment_fromstring-expanded"><a name="L89"></a><tt class="py-lineno"> 89</tt> <tt class="py-line"> <tt class="py-docstring">"""Parses a single HTML element; it is an error if there is more than</tt> </tt>
380 <a name="L90"></a><tt class="py-lineno"> 90</tt> <tt class="py-line"><tt class="py-docstring"> one element, or if anything but whitespace precedes or follows the</tt> </tt>
381 <a name="L91"></a><tt class="py-lineno"> 91</tt> <tt class="py-line"><tt class="py-docstring"> element.</tt> </tt>
382 <a name="L92"></a><tt class="py-lineno"> 92</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
383 <a name="L93"></a><tt class="py-lineno"> 93</tt> <tt class="py-line"><tt class="py-docstring"> If create_parent is true (or is a tag name) then a parent node</tt> </tt>
384 <a name="L94"></a><tt class="py-lineno"> 94</tt> <tt class="py-line"><tt class="py-docstring"> will be created to encapsulate the HTML in a single element. In</tt> </tt>
385 <a name="L95"></a><tt class="py-lineno"> 95</tt> <tt class="py-line"><tt class="py-docstring"> this case, leading or trailing text is allowed.</tt> </tt>
386 <a name="L96"></a><tt class="py-lineno"> 96</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
387 <a name="L97"></a><tt class="py-lineno"> 97</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt id="link-37" class="py-name"><a title="lxml.html
388 lxml.html.diff.href_token.html
389 lxml.html.diff.tag_token.html
390 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-37', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">_strings</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
391 <a name="L98"></a><tt class="py-lineno"> 98</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt class="py-name">TypeError</tt><tt class="py-op">(</tt><tt class="py-string">'string required'</tt><tt class="py-op">)</tt> </tt>
392 <a name="L99"></a><tt class="py-lineno"> 99</tt> <tt class="py-line"> </tt>
393 <a name="L100"></a><tt class="py-lineno">100</tt> <tt class="py-line"> <tt class="py-name">accept_leading_text</tt> <tt class="py-op">=</tt> <tt class="py-name">bool</tt><tt class="py-op">(</tt><tt class="py-name">create_parent</tt><tt class="py-op">)</tt> </tt>
394 <a name="L101"></a><tt class="py-lineno">101</tt> <tt class="py-line"> </tt>
395 <a name="L102"></a><tt class="py-lineno">102</tt> <tt class="py-line"> <tt class="py-name">elements</tt> <tt class="py-op">=</tt> <tt id="link-38" class="py-name" targets="Function lxml.html.fragments_fromstring()=lxml.html-module.html#fragments_fromstring,Function lxml.html.html5parser.fragments_fromstring()=lxml.html.html5parser-module.html#fragments_fromstring"><a title="lxml.html.fragments_fromstring
396 lxml.html.html5parser.fragments_fromstring" class="py-name" href="#" onclick="return doclink('link-38', 'fragments_fromstring', 'link-38');">fragments_fromstring</a></tt><tt class="py-op">(</tt> </tt>
397 <a name="L103"></a><tt class="py-lineno">103</tt> <tt class="py-line"> <tt id="link-39" class="py-name"><a title="lxml.html
398 lxml.html.diff.href_token.html
399 lxml.html.diff.tag_token.html
400 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-39', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">guess_charset</tt><tt class="py-op">,</tt> <tt id="link-40" class="py-name"><a title="lxml.etree._ElementTree.parser
401 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-40', 'parser', 'link-21');">parser</a></tt><tt class="py-op">=</tt><tt id="link-41" class="py-name"><a title="lxml.etree._ElementTree.parser
402 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-41', 'parser', 'link-21');">parser</a></tt><tt class="py-op">,</tt> </tt>
403 <a name="L104"></a><tt class="py-lineno">104</tt> <tt class="py-line"> <tt class="py-name">no_leading_text</tt><tt class="py-op">=</tt><tt class="py-keyword">not</tt> <tt class="py-name">accept_leading_text</tt><tt class="py-op">,</tt> <tt class="py-op">**</tt><tt class="py-name">kw</tt><tt class="py-op">)</tt> </tt>
404 <a name="L105"></a><tt class="py-lineno">105</tt> <tt class="py-line"> </tt>
405 <a name="L106"></a><tt class="py-lineno">106</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">create_parent</tt><tt class="py-op">:</tt> </tt>
406 <a name="L107"></a><tt class="py-lineno">107</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">create_parent</tt><tt class="py-op">,</tt> <tt class="py-name">basestring</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
407 <a name="L108"></a><tt class="py-lineno">108</tt> <tt class="py-line"> <tt class="py-name">create_parent</tt> <tt class="py-op">=</tt> <tt class="py-string">'div'</tt> </tt>
408 <a name="L109"></a><tt class="py-lineno">109</tt> <tt class="py-line"> <tt class="py-name">new_root</tt> <tt class="py-op">=</tt> <tt id="link-42" class="py-name" targets="Class lxml.cssselect.Element=lxml.cssselect.Element-class.html,Function lxml.etree.Element()=lxml.etree-module.html#Element,Function lxml.html.Element()=lxml.html-module.html#Element,Function lxml.objectify.Element()=lxml.objectify-module.html#Element,Method lxml.tests.test_pyclasslookup.PyClassLookupTestCase.Element()=lxml.tests.test_pyclasslookup.PyClassLookupTestCase-class.html#Element,Class xml.etree.ElementTree.Element=xml.etree.ElementTree.Element-class.html"><a title="lxml.cssselect.Element
411 lxml.objectify.Element
412 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.Element
413 xml.etree.ElementTree.Element" class="py-name" href="#" onclick="return doclink('link-42', 'Element', 'link-42');">Element</a></tt><tt class="py-op">(</tt><tt class="py-name">create_parent</tt><tt class="py-op">)</tt> </tt>
414 <a name="L110"></a><tt class="py-lineno">110</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">elements</tt><tt class="py-op">:</tt> </tt>
415 <a name="L111"></a><tt class="py-lineno">111</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">elements</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">,</tt> <tt class="py-name">basestring</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
416 <a name="L112"></a><tt class="py-lineno">112</tt> <tt class="py-line"> <tt class="py-name">new_root</tt><tt class="py-op">.</tt><tt id="link-43" class="py-name" targets="Variable lxml.etree.QName.text=lxml.etree.QName-class.html#text,Variable lxml.etree._AppendOnlyElementProxy.text=lxml.etree._AppendOnlyElementProxy-class.html#text,Variable lxml.etree._Element.text=lxml.etree._Element-class.html#text,Variable lxml.etree._Entity.text=lxml.etree._Entity-class.html#text,Variable lxml.etree._ModifyContentOnlyProxy.text=lxml.etree._ModifyContentOnlyProxy-class.html#text,Variable lxml.etree._ReadOnlyEntityProxy.text=lxml.etree._ReadOnlyEntityProxy-class.html#text,Variable lxml.etree._ReadOnlyProxy.text=lxml.etree._ReadOnlyProxy-class.html#text,Variable lxml.etree.__ContentOnlyElement.text=lxml.etree.__ContentOnlyElement-class.html#text,Variable lxml.objectify.ObjectifiedElement.text=lxml.objectify.ObjectifiedElement-class.html#text,Variable xml.etree.ElementTree.Element.text=xml.etree.ElementTree.Element-class.html#text"><a title="lxml.etree.QName.text
417 lxml.etree._AppendOnlyElementProxy.text
418 lxml.etree._Element.text
419 lxml.etree._Entity.text
420 lxml.etree._ModifyContentOnlyProxy.text
421 lxml.etree._ReadOnlyEntityProxy.text
422 lxml.etree._ReadOnlyProxy.text
423 lxml.etree.__ContentOnlyElement.text
424 lxml.objectify.ObjectifiedElement.text
425 xml.etree.ElementTree.Element.text" class="py-name" href="#" onclick="return doclink('link-43', 'text', 'link-43');">text</a></tt> <tt class="py-op">=</tt> <tt class="py-name">elements</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> </tt>
426 <a name="L113"></a><tt class="py-lineno">113</tt> <tt class="py-line"> <tt class="py-keyword">del</tt> <tt class="py-name">elements</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> </tt>
427 <a name="L114"></a><tt class="py-lineno">114</tt> <tt class="py-line"> <tt class="py-name">new_root</tt><tt class="py-op">.</tt><tt id="link-44" class="py-name" targets="Method lxml.etree._AppendOnlyElementProxy.extend()=lxml.etree._AppendOnlyElementProxy-class.html#extend,Method lxml.etree._Element.extend()=lxml.etree._Element-class.html#extend,Method lxml.etree._OpaqueDocumentWrapper.extend()=lxml.etree._OpaqueDocumentWrapper-class.html#extend"><a title="lxml.etree._AppendOnlyElementProxy.extend
428 lxml.etree._Element.extend
429 lxml.etree._OpaqueDocumentWrapper.extend" class="py-name" href="#" onclick="return doclink('link-44', 'extend', 'link-44');">extend</a></tt><tt class="py-op">(</tt><tt class="py-name">elements</tt><tt class="py-op">)</tt> </tt>
430 <a name="L115"></a><tt class="py-lineno">115</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">new_root</tt> </tt>
431 <a name="L116"></a><tt class="py-lineno">116</tt> <tt class="py-line"> </tt>
432 <a name="L117"></a><tt class="py-lineno">117</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">elements</tt><tt class="py-op">:</tt> </tt>
433 <a name="L118"></a><tt class="py-lineno">118</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt id="link-45" class="py-name"><a title="lxml.etree
434 lxml.sax.ElementTreeContentHandler.etree
435 lxml.tests.test_elementtree.CElementTreeTestCase.etree
436 lxml.tests.test_elementtree.ETreeTestCaseBase.etree
437 lxml.tests.test_io.IOTestCaseBase.etree" class="py-name" href="#" onclick="return doclink('link-45', 'etree', 'link-3');">etree</a></tt><tt class="py-op">.</tt><tt id="link-46" class="py-name"><a title="lxml.etree.ParserError" class="py-name" href="#" onclick="return doclink('link-46', 'ParserError', 'link-36');">ParserError</a></tt><tt class="py-op">(</tt><tt class="py-string">'No elements found'</tt><tt class="py-op">)</tt> </tt>
438 <a name="L119"></a><tt class="py-lineno">119</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">elements</tt><tt class="py-op">)</tt> <tt class="py-op">></tt> <tt class="py-number">1</tt><tt class="py-op">:</tt> </tt>
439 <a name="L120"></a><tt class="py-lineno">120</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt id="link-47" class="py-name"><a title="lxml.etree
440 lxml.sax.ElementTreeContentHandler.etree
441 lxml.tests.test_elementtree.CElementTreeTestCase.etree
442 lxml.tests.test_elementtree.ETreeTestCaseBase.etree
443 lxml.tests.test_io.IOTestCaseBase.etree" class="py-name" href="#" onclick="return doclink('link-47', 'etree', 'link-3');">etree</a></tt><tt class="py-op">.</tt><tt id="link-48" class="py-name"><a title="lxml.etree.ParserError" class="py-name" href="#" onclick="return doclink('link-48', 'ParserError', 'link-36');">ParserError</a></tt><tt class="py-op">(</tt><tt class="py-string">'Multiple elements found'</tt><tt class="py-op">)</tt> </tt>
444 <a name="L121"></a><tt class="py-lineno">121</tt> <tt class="py-line"> <tt class="py-name">result</tt> <tt class="py-op">=</tt> <tt class="py-name">elements</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> </tt>
445 <a name="L122"></a><tt class="py-lineno">122</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-49" class="py-name" targets="Variable lxml.etree._Element.tail=lxml.etree._Element-class.html#tail,Variable lxml.etree._ReadOnlyProxy.tail=lxml.etree._ReadOnlyProxy-class.html#tail,Variable xml.etree.ElementTree.Element.tail=xml.etree.ElementTree.Element-class.html#tail"><a title="lxml.etree._Element.tail
446 lxml.etree._ReadOnlyProxy.tail
447 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-49', 'tail', 'link-49');">tail</a></tt> <tt class="py-keyword">and</tt> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-50" class="py-name"><a title="lxml.etree._Element.tail
448 lxml.etree._ReadOnlyProxy.tail
449 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-50', 'tail', 'link-49');">tail</a></tt><tt class="py-op">.</tt><tt id="link-51" class="py-name"><a title="lxml.doctestcompare.strip" class="py-name" href="#" onclick="return doclink('link-51', 'strip', 'link-34');">strip</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
450 <a name="L123"></a><tt class="py-lineno">123</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt id="link-52" class="py-name"><a title="lxml.etree
451 lxml.sax.ElementTreeContentHandler.etree
452 lxml.tests.test_elementtree.CElementTreeTestCase.etree
453 lxml.tests.test_elementtree.ETreeTestCaseBase.etree
454 lxml.tests.test_io.IOTestCaseBase.etree" class="py-name" href="#" onclick="return doclink('link-52', 'etree', 'link-3');">etree</a></tt><tt class="py-op">.</tt><tt id="link-53" class="py-name"><a title="lxml.etree.ParserError" class="py-name" href="#" onclick="return doclink('link-53', 'ParserError', 'link-36');">ParserError</a></tt><tt class="py-op">(</tt><tt class="py-string">'Element followed by text: %r'</tt> <tt class="py-op">%</tt> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-54" class="py-name"><a title="lxml.etree._Element.tail
455 lxml.etree._ReadOnlyProxy.tail
456 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-54', 'tail', 'link-49');">tail</a></tt><tt class="py-op">)</tt> </tt>
457 <a name="L124"></a><tt class="py-lineno">124</tt> <tt class="py-line"> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-55" class="py-name"><a title="lxml.etree._Element.tail
458 lxml.etree._ReadOnlyProxy.tail
459 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-55', 'tail', 'link-49');">tail</a></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
460 <a name="L125"></a><tt class="py-lineno">125</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">result</tt> </tt>
461 </div><a name="L126"></a><tt class="py-lineno">126</tt> <tt class="py-line"> </tt>
462 <a name="L127"></a><tt class="py-lineno">127</tt> <tt class="py-line"> </tt>
463 <a name="fromstring"></a><div id="fromstring-def"><a name="L128"></a><tt class="py-lineno">128</tt> <a class="py-toggle" href="#" id="fromstring-toggle" onclick="return toggle('fromstring');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#fromstring">fromstring</a><tt class="py-op">(</tt><tt class="py-param">html</tt><tt class="py-op">,</tt> <tt class="py-param">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">,</tt> <tt class="py-param">parser</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
464 </div><div id="fromstring-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="fromstring-expanded"><a name="L129"></a><tt class="py-lineno">129</tt> <tt class="py-line"> <tt class="py-docstring">"""Parse the html, returning a single element/document.</tt> </tt>
465 <a name="L130"></a><tt class="py-lineno">130</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
466 <a name="L131"></a><tt class="py-lineno">131</tt> <tt class="py-line"><tt class="py-docstring"> This tries to minimally parse the chunk of text, without knowing if it</tt> </tt>
467 <a name="L132"></a><tt class="py-lineno">132</tt> <tt class="py-line"><tt class="py-docstring"> is a fragment or a document.</tt> </tt>
468 <a name="L133"></a><tt class="py-lineno">133</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
469 <a name="L134"></a><tt class="py-lineno">134</tt> <tt class="py-line"><tt class="py-docstring"> base_url will set the document's base_url attribute (and the tree's docinfo.URL)</tt> </tt>
470 <a name="L135"></a><tt class="py-lineno">135</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
471 <a name="L136"></a><tt class="py-lineno">136</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt id="link-56" class="py-name"><a title="lxml.html
472 lxml.html.diff.href_token.html
473 lxml.html.diff.tag_token.html
474 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-56', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt class="py-name">_strings</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
475 <a name="L137"></a><tt class="py-lineno">137</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt class="py-name">TypeError</tt><tt class="py-op">(</tt><tt class="py-string">'string required'</tt><tt class="py-op">)</tt> </tt>
476 <a name="L138"></a><tt class="py-lineno">138</tt> <tt class="py-line"> <tt class="py-name">doc</tt> <tt class="py-op">=</tt> <tt id="link-57" class="py-name" targets="Function lxml.html.document_fromstring()=lxml.html-module.html#document_fromstring,Function lxml.html.html5parser.document_fromstring()=lxml.html.html5parser-module.html#document_fromstring"><a title="lxml.html.document_fromstring
477 lxml.html.html5parser.document_fromstring" class="py-name" href="#" onclick="return doclink('link-57', 'document_fromstring', 'link-57');">document_fromstring</a></tt><tt class="py-op">(</tt><tt id="link-58" class="py-name"><a title="lxml.html
478 lxml.html.diff.href_token.html
479 lxml.html.diff.tag_token.html
480 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-58', 'html', 'link-5');">html</a></tt><tt class="py-op">,</tt> <tt id="link-59" class="py-name"><a title="lxml.etree._ElementTree.parser
481 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-59', 'parser', 'link-21');">parser</a></tt><tt class="py-op">=</tt><tt id="link-60" class="py-name"><a title="lxml.etree._ElementTree.parser
482 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-60', 'parser', 'link-21');">parser</a></tt><tt class="py-op">,</tt> </tt>
483 <a name="L139"></a><tt class="py-lineno">139</tt> <tt class="py-line"> <tt class="py-name">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">guess_charset</tt><tt class="py-op">)</tt> </tt>
484 <a name="L140"></a><tt class="py-lineno">140</tt> <tt class="py-line"> </tt>
485 <a name="L141"></a><tt class="py-lineno">141</tt> <tt class="py-line"> <tt class="py-comment"># document starts with doctype or <html>, full document!</tt> </tt>
486 <a name="L142"></a><tt class="py-lineno">142</tt> <tt class="py-line"> <tt id="link-61" class="py-name" targets="Method lxml.etree.TreeBuilder.start()=lxml.etree.TreeBuilder-class.html#start"><a title="lxml.etree.TreeBuilder.start" class="py-name" href="#" onclick="return doclink('link-61', 'start', 'link-61');">start</a></tt> <tt class="py-op">=</tt> <tt id="link-62" class="py-name"><a title="lxml.html
487 lxml.html.diff.href_token.html
488 lxml.html.diff.tag_token.html
489 lxml.html.diff.token.html" class="py-name" href="#" onclick="return doclink('link-62', 'html', 'link-5');">html</a></tt><tt class="py-op">[</tt><tt class="py-op">:</tt><tt class="py-number">50</tt><tt class="py-op">]</tt><tt class="py-op">.</tt><tt class="py-name">lstrip</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">.</tt><tt class="py-name">lower</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
490 <a name="L143"></a><tt class="py-lineno">143</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-63" class="py-name"><a title="lxml.etree.TreeBuilder.start" class="py-name" href="#" onclick="return doclink('link-63', 'start', 'link-61');">start</a></tt><tt class="py-op">.</tt><tt class="py-name">startswith</tt><tt class="py-op">(</tt><tt class="py-string">'<html'</tt><tt class="py-op">)</tt> <tt class="py-keyword">or</tt> <tt id="link-64" class="py-name"><a title="lxml.etree.TreeBuilder.start" class="py-name" href="#" onclick="return doclink('link-64', 'start', 'link-61');">start</a></tt><tt class="py-op">.</tt><tt class="py-name">startswith</tt><tt class="py-op">(</tt><tt class="py-string">'<!doctype'</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
491 <a name="L144"></a><tt class="py-lineno">144</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">doc</tt> </tt>
492 <a name="L145"></a><tt class="py-lineno">145</tt> <tt class="py-line"> </tt>
493 <a name="L146"></a><tt class="py-lineno">146</tt> <tt class="py-line"> <tt id="link-65" class="py-name" targets="Variable lxml.html.HtmlMixin.head=lxml.html.HtmlMixin-class.html#head"><a title="lxml.html.HtmlMixin.head" class="py-name" href="#" onclick="return doclink('link-65', 'head', 'link-65');">head</a></tt> <tt class="py-op">=</tt> <tt id="link-66" class="py-name" targets="Function lxml.html.html5parser._find_tag()=lxml.html.html5parser-module.html#_find_tag"><a title="lxml.html.html5parser._find_tag" class="py-name" href="#" onclick="return doclink('link-66', '_find_tag', 'link-66');">_find_tag</a></tt><tt class="py-op">(</tt><tt class="py-name">doc</tt><tt class="py-op">,</tt> <tt class="py-string">'head'</tt><tt class="py-op">)</tt> </tt>
494 <a name="L147"></a><tt class="py-lineno">147</tt> <tt class="py-line"> </tt>
495 <a name="L148"></a><tt class="py-lineno">148</tt> <tt class="py-line"> <tt class="py-comment"># if the head is not empty we have a full document</tt> </tt>
496 <a name="L149"></a><tt class="py-lineno">149</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">len</tt><tt class="py-op">(</tt><tt id="link-67" class="py-name"><a title="lxml.html.HtmlMixin.head" class="py-name" href="#" onclick="return doclink('link-67', 'head', 'link-65');">head</a></tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
497 <a name="L150"></a><tt class="py-lineno">150</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">doc</tt> </tt>
498 <a name="L151"></a><tt class="py-lineno">151</tt> <tt class="py-line"> </tt>
499 <a name="L152"></a><tt class="py-lineno">152</tt> <tt class="py-line"> <tt id="link-68" class="py-name" targets="Variable lxml.html.HtmlMixin.body=lxml.html.HtmlMixin-class.html#body"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-68', 'body', 'link-68');">body</a></tt> <tt class="py-op">=</tt> <tt id="link-69" class="py-name"><a title="lxml.html.html5parser._find_tag" class="py-name" href="#" onclick="return doclink('link-69', '_find_tag', 'link-66');">_find_tag</a></tt><tt class="py-op">(</tt><tt class="py-name">doc</tt><tt class="py-op">,</tt> <tt class="py-string">'body'</tt><tt class="py-op">)</tt> </tt>
500 <a name="L153"></a><tt class="py-lineno">153</tt> <tt class="py-line"> </tt>
501 <a name="L154"></a><tt class="py-lineno">154</tt> <tt class="py-line"> <tt class="py-comment"># The body has just one element, so it was probably a single</tt> </tt>
502 <a name="L155"></a><tt class="py-lineno">155</tt> <tt class="py-line"> <tt class="py-comment"># element passed in</tt> </tt>
503 <a name="L156"></a><tt class="py-lineno">156</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-op">(</tt><tt class="py-name">len</tt><tt class="py-op">(</tt><tt id="link-70" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-70', 'body', 'link-68');">body</a></tt><tt class="py-op">)</tt> <tt class="py-op">==</tt> <tt class="py-number">1</tt> <tt class="py-keyword">and</tt> <tt class="py-op">(</tt><tt class="py-keyword">not</tt> <tt id="link-71" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-71', 'body', 'link-68');">body</a></tt><tt class="py-op">.</tt><tt id="link-72" class="py-name"><a title="lxml.etree.QName.text
504 lxml.etree._AppendOnlyElementProxy.text
505 lxml.etree._Element.text
506 lxml.etree._Entity.text
507 lxml.etree._ModifyContentOnlyProxy.text
508 lxml.etree._ReadOnlyEntityProxy.text
509 lxml.etree._ReadOnlyProxy.text
510 lxml.etree.__ContentOnlyElement.text
511 lxml.objectify.ObjectifiedElement.text
512 xml.etree.ElementTree.Element.text" class="py-name" href="#" onclick="return doclink('link-72', 'text', 'link-43');">text</a></tt> <tt class="py-keyword">or</tt> <tt class="py-keyword">not</tt> <tt id="link-73" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-73', 'body', 'link-68');">body</a></tt><tt class="py-op">.</tt><tt id="link-74" class="py-name"><a title="lxml.etree.QName.text
513 lxml.etree._AppendOnlyElementProxy.text
514 lxml.etree._Element.text
515 lxml.etree._Entity.text
516 lxml.etree._ModifyContentOnlyProxy.text
517 lxml.etree._ReadOnlyEntityProxy.text
518 lxml.etree._ReadOnlyProxy.text
519 lxml.etree.__ContentOnlyElement.text
520 lxml.objectify.ObjectifiedElement.text
521 xml.etree.ElementTree.Element.text" class="py-name" href="#" onclick="return doclink('link-74', 'text', 'link-43');">text</a></tt><tt class="py-op">.</tt><tt id="link-75" class="py-name"><a title="lxml.doctestcompare.strip" class="py-name" href="#" onclick="return doclink('link-75', 'strip', 'link-34');">strip</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
522 <a name="L157"></a><tt class="py-lineno">157</tt> <tt class="py-line"> <tt class="py-keyword">and</tt> <tt class="py-op">(</tt><tt class="py-keyword">not</tt> <tt id="link-76" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-76', 'body', 'link-68');">body</a></tt><tt class="py-op">[</tt><tt class="py-op">-</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">.</tt><tt id="link-77" class="py-name"><a title="lxml.etree._Element.tail
523 lxml.etree._ReadOnlyProxy.tail
524 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-77', 'tail', 'link-49');">tail</a></tt> <tt class="py-keyword">or</tt> <tt class="py-keyword">not</tt> <tt id="link-78" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-78', 'body', 'link-68');">body</a></tt><tt class="py-op">[</tt><tt class="py-op">-</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">.</tt><tt id="link-79" class="py-name"><a title="lxml.etree._Element.tail
525 lxml.etree._ReadOnlyProxy.tail
526 xml.etree.ElementTree.Element.tail" class="py-name" href="#" onclick="return doclink('link-79', 'tail', 'link-49');">tail</a></tt><tt class="py-op">.</tt><tt id="link-80" class="py-name"><a title="lxml.doctestcompare.strip" class="py-name" href="#" onclick="return doclink('link-80', 'strip', 'link-34');">strip</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
527 <a name="L158"></a><tt class="py-lineno">158</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-81" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-81', 'body', 'link-68');">body</a></tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> </tt>
528 <a name="L159"></a><tt class="py-lineno">159</tt> <tt class="py-line"> </tt>
529 <a name="L160"></a><tt class="py-lineno">160</tt> <tt class="py-line"> <tt class="py-comment"># Now we have a body which represents a bunch of tags which have the</tt> </tt>
530 <a name="L161"></a><tt class="py-lineno">161</tt> <tt class="py-line"> <tt class="py-comment"># content that was passed in. We will create a fake container, which</tt> </tt>
531 <a name="L162"></a><tt class="py-lineno">162</tt> <tt class="py-line"> <tt class="py-comment"># is the body tag, except <body> implies too much structure.</tt> </tt>
532 <a name="L163"></a><tt class="py-lineno">163</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-82" class="py-name"><a title="lxml.html._contains_block_level_tag
533 lxml.html.diff._contains_block_level_tag" class="py-name" href="#" onclick="return doclink('link-82', '_contains_block_level_tag', 'link-6');">_contains_block_level_tag</a></tt><tt class="py-op">(</tt><tt id="link-83" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-83', 'body', 'link-68');">body</a></tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
534 <a name="L164"></a><tt class="py-lineno">164</tt> <tt class="py-line"> <tt id="link-84" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-84', 'body', 'link-68');">body</a></tt><tt class="py-op">.</tt><tt id="link-85" class="py-name"><a title="lxml.etree._Comment.tag
535 lxml.etree._Element.tag
536 lxml.etree._Entity.tag
537 lxml.etree._ProcessingInstruction.tag
538 lxml.etree._ReadOnlyProxy.tag
539 lxml.tests.test_xpathevaluator.tag
540 xml.etree.ElementTree.Element.tag" class="py-name" href="#" onclick="return doclink('link-85', 'tag', 'link-16');">tag</a></tt> <tt class="py-op">=</tt> <tt class="py-string">'div'</tt> </tt>
541 <a name="L165"></a><tt class="py-lineno">165</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
542 <a name="L166"></a><tt class="py-lineno">166</tt> <tt class="py-line"> <tt id="link-86" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-86', 'body', 'link-68');">body</a></tt><tt class="py-op">.</tt><tt id="link-87" class="py-name"><a title="lxml.etree._Comment.tag
543 lxml.etree._Element.tag
544 lxml.etree._Entity.tag
545 lxml.etree._ProcessingInstruction.tag
546 lxml.etree._ReadOnlyProxy.tag
547 lxml.tests.test_xpathevaluator.tag
548 xml.etree.ElementTree.Element.tag" class="py-name" href="#" onclick="return doclink('link-87', 'tag', 'link-16');">tag</a></tt> <tt class="py-op">=</tt> <tt class="py-string">'span'</tt> </tt>
549 <a name="L167"></a><tt class="py-lineno">167</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-88" class="py-name"><a title="lxml.html.HtmlMixin.body" class="py-name" href="#" onclick="return doclink('link-88', 'body', 'link-68');">body</a></tt> </tt>
550 </div><a name="L168"></a><tt class="py-lineno">168</tt> <tt class="py-line"> </tt>
551 <a name="L169"></a><tt class="py-lineno">169</tt> <tt class="py-line"> </tt>
552 <a name="parse"></a><div id="parse-def"><a name="L170"></a><tt class="py-lineno">170</tt> <a class="py-toggle" href="#" id="parse-toggle" onclick="return toggle('parse');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="lxml.html.html5parser-module.html#parse">parse</a><tt class="py-op">(</tt><tt class="py-param">filename_url_or_file</tt><tt class="py-op">,</tt> <tt class="py-param">guess_charset</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">,</tt> <tt class="py-param">parser</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
553 </div><div id="parse-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="parse-expanded"><a name="L171"></a><tt class="py-lineno">171</tt> <tt class="py-line"> <tt class="py-docstring">"""Parse a filename, URL, or file-like object into an HTML document</tt> </tt>
554 <a name="L172"></a><tt class="py-lineno">172</tt> <tt class="py-line"><tt class="py-docstring"> tree. Note: this returns a tree, not an element. Use</tt> </tt>
555 <a name="L173"></a><tt class="py-lineno">173</tt> <tt class="py-line"><tt class="py-docstring"> ``parse(...).getroot()`` to get the document root.</tt> </tt>
556 <a name="L174"></a><tt class="py-lineno">174</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
557 <a name="L175"></a><tt class="py-lineno">175</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-89" class="py-name"><a title="lxml.etree._ElementTree.parser
558 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-89', 'parser', 'link-21');">parser</a></tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
559 <a name="L176"></a><tt class="py-lineno">176</tt> <tt class="py-line"> <tt id="link-90" class="py-name"><a title="lxml.etree._ElementTree.parser
560 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-90', 'parser', 'link-21');">parser</a></tt> <tt class="py-op">=</tt> <tt id="link-91" class="py-name"><a title="lxml.html.html5parser.html_parser
561 lxml.html.html_parser" class="py-name" href="#" onclick="return doclink('link-91', 'html_parser', 'link-23');">html_parser</a></tt> </tt>
562 <a name="L177"></a><tt class="py-lineno">177</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">filename_url_or_file</tt><tt class="py-op">,</tt> <tt class="py-name">basestring</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
563 <a name="L178"></a><tt class="py-lineno">178</tt> <tt class="py-line"> <tt class="py-name">fp</tt> <tt class="py-op">=</tt> <tt class="py-name">urllib</tt><tt class="py-op">.</tt><tt class="py-name">urlopen</tt><tt class="py-op">(</tt><tt class="py-name">filename_url_or_file</tt><tt class="py-op">)</tt> </tt>
564 <a name="L179"></a><tt class="py-lineno">179</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
565 <a name="L180"></a><tt class="py-lineno">180</tt> <tt class="py-line"> <tt class="py-name">fp</tt> <tt class="py-op">=</tt> <tt class="py-name">filename_url_or_file</tt> </tt>
566 <a name="L181"></a><tt class="py-lineno">181</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-92" class="py-name"><a title="lxml.etree._ElementTree.parser
567 lxml.tests.test_pyclasslookup.PyClassLookupTestCase.parser" class="py-name" href="#" onclick="return doclink('link-92', 'parser', 'link-21');">parser</a></tt><tt class="py-op">.</tt><tt id="link-93" class="py-name"><a title="lxml.cssselect.parse
568 lxml.etree._ElementTree.parse
570 lxml.html.ElementSoup.parse
571 lxml.html.html5parser.parse
573 lxml.html.soupparser.parse
575 lxml.tests.common_imports.HelperTestCase.parse" class="py-name" href="#" onclick="return doclink('link-93', 'parse', 'link-25');">parse</a></tt><tt class="py-op">(</tt><tt class="py-name">fp</tt><tt class="py-op">,</tt> <tt class="py-name">useChardet</tt><tt class="py-op">=</tt><tt class="py-name">guess_charset</tt><tt class="py-op">)</tt> </tt>
576 </div><a name="L182"></a><tt class="py-lineno">182</tt> <tt class="py-line"> </tt>
577 <a name="L183"></a><tt class="py-lineno">183</tt> <tt class="py-line"> </tt>
578 <a name="L184"></a><tt class="py-lineno">184</tt> <tt class="py-line"><tt id="link-94" class="py-name"><a title="lxml.html.html5parser.html_parser
579 lxml.html.html_parser" class="py-name" href="#" onclick="return doclink('link-94', 'html_parser', 'link-23');">html_parser</a></tt> <tt class="py-op">=</tt> <tt id="link-95" class="py-name"><a title="lxml.etree.HTMLParser
581 lxml.html.html5parser.HTMLParser" class="py-name" href="#" onclick="return doclink('link-95', 'HTMLParser', 'link-0');">HTMLParser</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
582 <a name="L185"></a><tt class="py-lineno">185</tt> <tt class="py-line"> </tt><script type="text/javascript">
584 expandto(location.href);
589 <!-- ==================== NAVIGATION BAR ==================== -->
590 <table class="navbar" border="0" width="100%" cellpadding="0"
591 bgcolor="#a0c0ff" cellspacing="0">
594 <th> <a
595 href="lxml-module.html">Home</a> </th>
598 <th> <a
599 href="module-tree.html">Trees</a> </th>
602 <th> <a
603 href="identifier-index.html">Indices</a> </th>
606 <th> <a
607 href="help.html">Help</a> </th>
609 <!-- Project homepage -->
610 <th class="navbar" align="right" width="100%">
611 <table border="0" cellpadding="0" cellspacing="0">
612 <tr><th class="navbar" align="center"
613 ><a class="navbar" target="_top" href="/">lxml API</a></th>
617 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
619 <td align="left" class="footer">
620 Generated by Epydoc 3.0.1 on Tue Jul 31 10:14:22 2012
622 <td align="right" class="footer">
623 <a target="mainFrame" href="http://epydoc.sourceforge.net"
624 >http://epydoc.sourceforge.net</a>
629 <script type="text/javascript">
631 // Private objects are initially displayed (because if
632 // javascript is turned off then we want them to be
633 // visible); but by default, we want to hide them. So hide
634 // them unless we have a cookie that says to show them.