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