parent
5b529be289
commit
be24181e39
@ -1,17 +1,18 @@
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
html="""
|
html="""
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<h1>Page Title</h1>
|
<h1>Page Title</h1>
|
||||||
<p>Some text.</p>
|
<p>Some text.</p>
|
||||||
<h2>Section 1</h2>
|
<h2>Section 1</h2>
|
||||||
<p>More text.</p>
|
<p>More text.</p>
|
||||||
<h2>Section 2</h2>
|
<h2>Section 2</h2>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
"""
|
"""
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
selector = etree.HTML(html)
|
selector = etree.HTML(html)
|
||||||
#修改xpath表达式
|
#修改xpath表达式
|
||||||
result = selector.xpath('//h2')
|
result = selector.xpath('//h2')
|
||||||
print(result)
|
print(result)
|
||||||
|
printf(selector)
|
Loading…
Reference in new issue