Get href value in Splinter?

2020-06-16 05:57发布

I would like to get href value from <a> element in Splinter.

Is there any api method for that?

2条回答
在下西门庆
2楼-- · 2020-06-16 06:30

If you are selecting elements using the find_by_* methods, instances returned by these are ElementLists. After you select the element you are interested in (most probably an ElementAPI instance), access the property like a dictionary:

the_element['href']
查看更多
三岁会撩人
3楼-- · 2020-06-16 06:31
#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"])
查看更多
登录 后发表回答