Get href value in Splinter?
Asked Answered
C

2

8

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

Is there any api method for that?

Conjugate answered 16/2, 2014 at 20:49 Comment(0)
S
11

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']
Sitting answered 16/2, 2014 at 21:9 Comment(1)
Too bad element['href'] returns an absolute URL (at least under Firefox), not the actual property, as in HTML, which may be relative.Sublittoral
C
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"])
Constitution answered 23/1, 2015 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.