【发布时间】:2014-07-26 18:00:42
【问题描述】:
<form method="post" name="login_form" action="/submit">
我正在尝试获取 action 属性 我试过了
print fromstring(source).xpath('.//form[@action]')[0].text,但它会打印出来
None
【问题讨论】:
<form method="post" name="login_form" action="/submit">
我正在尝试获取 action 属性 我试过了
print fromstring(source).xpath('.//form[@action]')[0].text,但它会打印出来
None
【问题讨论】:
您的 XPath 表达式返回 <form> 元素,而不是属性。
从元素中获取属性:
print fromstring(source).xpath('.//form[@action]')[0].get('action')
【讨论】: