我对lxml很陌生,我希望解析由“请求”检索的页面。我的html是:
<html>
<body>
<h1 class="entry-title">
<a href="http://a.com" rel="bookmark">
bla bla bla
</a>
</h1>
</body>
</html>我想要一根看起来像这样的绳子:
"""<h1 class="entry-title">
<a href="http://google.com" rel="bookmark">
bla bla bla
</a>
</h1>"""Python3.4中的代码是什么?
发布于 2014-12-08 12:27:04
试着做这样的事情:
from lxml.html import document_fromstring
from lxml.html import tostring
doc = document_fromstring(YOUR_HTML_STRING)
h1 = tostring(doc.xpath("//h1")[0])https://stackoverflow.com/questions/27343485
复制相似问题