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!
asked Dec 21, 2015 at 0:28
kevin
2,0145 gold badges27 silver badges30 bronze badges
1 Answer 1
This worked.
desc = data.xpath("//td")
print desc.text_content()
answered Dec 21, 2015 at 0:44
kevin
2,0145 gold badges27 silver badges30 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
//td//text()?desc.replace("\n"," ")?