8

我想从Splinter 中的元素中获取href价值。<a>

有什么api方法吗?

4

2 回答 2

11

如果您使用find_by_* 方法选择元素,则这些返回的实例是ElementLists。选择您感兴趣的元素(很可能是一个ElementAPI实例)后,像字典一样访问该属性:

the_element['href']
于 2014-02-16T21:09:45.227 回答
1
#simplest possible working example demonstrating this in action
import splinter
b = splinter.Browser()
b.visit("http://www.google.com")
elems = b.find_by_tag("a")
for e in elems:
    print(e["href"])
于 2015-01-23T19:20:07.297 回答