2

How can I extract the entire content within "td"?

<td>
    Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! 
    <span class="excitingNote">8 entire dolls per set! Octuple the presents!</span>
</td>

I tried this:

desc = data.xpath("//td/text()") 
print desc

But, it returns the first sentence only:

Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! 

I would like to have the output in the following format:

Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! 8 entire dolls per set! Octuple the presents!

I also tried:

desc = data.xpath("//td//text()") 
    print desc

The output looks like this:

Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! 
8 entire dolls per set! Octuple the presents!

I prefer the following:

Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! 8 entire dolls per set! Octuple the presents!
3
  • shouldn't it be //td//text()? Commented Dec 21, 2015 at 0:32
  • please see my revised question. Commented Dec 21, 2015 at 0:37
  • 2
    desc.replace("\n"," ") ? Commented Dec 21, 2015 at 0:38

1 Answer 1

2

This worked.

desc = data.xpath("//td") 
    print desc.text_content()
Sign up to request clarification or add additional context in comments.

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.