1

Tried extracting the href from:

<a lang="en" class="new class" href="/abc/stack.com" 
tabindex="-1" data-type="itemTitles"><span><mark>Scott</mark>, CC042<br></span></a>

using elems = driver.find_elements_by_css_selector(".new class [href]") , but doesn't seem to work.

Also tried Python Selenium - get href value, but it returned an empty list.

So I want to extract all the href elements of class = "new class" as mentioned above and append them in a list

Thanks!!

0

2 Answers 2

2

Use .get_attribute('href').

by_css_selector:

elems = driver.find_elements_by_css_selector('.new.class')
for elem in elems:
    print(elem.get_attribute('href'))

Or by_xpath:

elems = driver.find_elements_by_xpath('//a[@class="new class"]')
Sign up to request clarification or add additional context in comments.

Comments

0

Just change it to

elems = driver.find_elements_by_css_selector(".new.class[href]")

OR

elems = driver.find_elements_by_css_selector("[class='new class'][href]")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.