XPath 怎么获取多个值?

2016-06-20 23:59:31 +08:00
 erevus

语言 python ,怎么获取 tr 里的 name 和 td[last()]的 comment()的值,或者不用 XPaht 也可以..

<tr mot="hideTip" mor="showTip" ck="detailAccount" un="userline" name="张三" class="cursor_point" alias="zhulei@test.com" href="#mbr/account/detail/zhulei@test.com,m=6859780" uid="2614939503">
  <td class="name">
    <span class="ico_move"></span>
    <input type="checkbox" name="alias" ck="checkThis" un="mbrCheck" title="选中 /取消选中" alias="zhulei@test.com" uin="2614939503" mobile="" nickname="张三" active="1" close="0">
    <span>
      <img class="icon_diff icon_man" src="https://res.mail.qq.com/bizmail/zh_CN/htmledition/images/spacer087795.gif" title="男">
      <a un="name" class="" href="#mbr/account/detail/zhulei@test.com,m=6859780">
        <span>张三</span></a>
    </span>
  </td>
  <td class="email">
    <a href="#mbr/account/detail/zhulei@test.com,m=6859780">
      <span>zhulei@test.com</span></a>
  </td>
  <td>
    <span title="公司名称">公司名称</span></td>
  <td un="settop">
    <a href="javascript:;" style="display:none" title="当前部门内置顶" un="tip" ck="setTop" class="set_toTop btn_gray" partyuserid="798874">
      <span>置顶</span></a>
  </td>
  <td>
    <!--open -1 off --></td>
  <td>
    <!--token 1 on -->
    <a href="javascript:;" title="已启用微信动态密码" class="dynamic_pwd" partyuserid="798874">
      <span></span>
    </a>
  </td>
</tr>
2310 次点击
所在节点    问与答
3 条回复
Hodor
2016-06-21 00:11:11 +08:00
bilibili
pandada8
2016-06-21 00:29:51 +08:00
for i in tree.xpath("//tr[@name]"):
print(i.attrib['name'], i.xpath("./td[last()]/comment()")[0])
erevus
2016-06-21 09:15:15 +08:00
@pandada8 长亭菊苣就是厉害

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/287172

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX