我在使用BeautifulSoup Select 文本时遇到问题.我试图只从<span class= "data">
中获取文本,但我也在其他元素中不断获得结果.例如,在下面的代码中,我想要的单词是"Playstation 3"和"Game Boy Advance",而不是"PC",你能帮忙吗?
汤:
<span class="data">
PlayStation 3
</span>,
<span class="data">
Game Boy Advance
</span>,
<span class="data">
Dec 8, 2022
</span>,
<span class="data">
<a href="/game/pc">
PC
</a>
P、 我在下面试过这个
console = soup.select('span.data')
for console in console:
print(console.get_text(strip = True))
输出代码段:
PlayStation 3
Game Boy Advance
Dec 8, 2022
PC
谢谢