gpt4 book ai didi

python - 网页抓取 - Python

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:03 24 4
gpt4 key购买 nike

如何提取“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>

我试过这个:

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

但是,它只返回第一句话:

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

我想要以下格式的输出:

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!

我也试过:

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

输出看起来像这样:

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!

我更喜欢以下内容:

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!

最佳答案

这有效。

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

关于python - 网页抓取 - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com