from lxml import etree html="""

Page Title

Some text.

Section 1

More text.

Section 2

""" from lxml import etree selector = etree.HTML(html) #修改xpath表达式 result = selector.xpath('//h2') print(result) printf(selector)