stochastic learner
stochastic learner

Reputation: 199

How do I get href attribute value from the given HTML using Python+Selenium?

I have HTML as shown (modified to make it brief)

ht=<a class="title" href="http:/www.myref.com/1235" title="This is link to my ref">This is my ref</a>

Now from here, I want to extract the "http:/www.myref.com/1235"

ht.get_text()

gives me only the text part This is my ref.

Upvotes: 1

Views: 783

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

If ht is a webelement then,

ht.get_attribute('href')

should give you http:/www.myref.com/1235

Since you are getting TypeError: 'NoneType' object is not callable

This could mean either

  1. ht is not a web element.

  2. ht is not rendered properly.

Put some delay before ht and try again with ht.get_attribute('href')

Upvotes: 1

Related Questions