1

Trying to figure out how to access the text in the screenshot below without pulling all the span tags.

Doing element = driver.find_elements_by_id('response') gives me a list, but I can't seem to dig down further to access the text I want.

I also tried this after doing some searching:

element = driver.find_element_by_xpath("//div[@id='response']/pre")

But I get the same result.

Any tips?

enter image description here

4
  • Doing element = driver.find_elements_by_id('response') gives me a list <--- Have you tried just element = driver.find_element_by_id('response')? Commented Jan 7, 2016 at 23:54
  • Yeah, that also gives me a long list with all the span tags. Commented Jan 7, 2016 at 23:57
  • Hmm...can you give us the link of that website? Commented Jan 7, 2016 at 23:59
  • Unfortunately none of this code loads until after inputting a bunch of fields, so won't really help Commented Jan 8, 2016 at 0:04

3 Answers 3

1

element.get_attribute('innerHTML')

this will help you to get the text between two div tag

Sign up to request clarification or add additional context in comments.

Comments

0
element.text

Should give out the contents of the element without any HTML tags.

Comments

0

In the case of the text being in the pure div the text is not extracted using element.text

Example:

<div>the text here</div>

I recommend to use a library called html2text and next:

html2text(element.get_attribute("outerHTML"))

It will do the trick!

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.