擅长:python、mysql、java
<pre><code>import lxml.etree as ET
body = t.xpath("//body");
for tag in body:
h = html.fromstring( ET.tostring(tag[0]) ).xpath("//h1");
p = html.fromstring( ET.tostring(tag[1]) ).xpath("//p");
htext = h[0].text_content();
ptext = h[0].text_content();
</code></pre>
<p>您还可以使用<code>.get('href')</code>作为标记,使用<code>.attrib</code>作为属性</p>
<p>这里的标记no是硬编码的,但是您也可以动态地执行此操作</p>