【问题标题】:Python - xpath syntax for a form (lxml.html)Python - 表单的 xpath 语法 (lxml.html)
【发布时间】:2014-07-26 18:00:42
【问题描述】:
<form method="post" name="login_form" action="/submit">

我正在尝试获取 action 属性 我试过了

print fromstring(source).xpath('.//form[@action]')[0].text,但它会打印出来

None

【问题讨论】:

    标签: python lxml.html


    【解决方案1】:

    您的 XPath 表达式返回 &lt;form&gt; 元素,而不是属性。

    从元素中获取属性:

    print fromstring(source).xpath('.//form[@action]')[0].get('action')
    

    【讨论】:

      猜你喜欢
      • 2014-03-28
      • 2017-05-07
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      相关资源
      最近更新 更多