用美丽的汤选择嵌套元素 [英] Selecting nested element with beautiful soup

查看:86
本文介绍了用美丽的汤选择嵌套元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html:

 < div class =leftColumn> 
< div>
< div class =static>
text1
< br>
text2
< br>
(222)123 - 4567
< br>
< div class =summary>

如何仅使用美丽的汤来选择文本行



我试过了很多类似的东西:

  soup.select('。leftColumn div') .text 

但至今没有骰子

解决方案

BeautifouSoup 选择查找列表。您必须指定索引。

  soup.select('。leftColumn div')[0] .text.split()


I have the following html:

<div class="leftColumn">
  <div>
     <div class="static">
     text1
     <br>
     text2
     <br>
     (222) 123 - 4567
     <br>
     <div class="summary">

How can I select just the text lines using beautiful soup.

I've tried a variety of things like:

soup.select('.leftColumn div').text

but so far no dice

解决方案

BeautifouSoup select retrives a list. You must specify the index.

soup.select('.leftColumn div')[0].text.split()

这篇关于用美丽的汤选择嵌套元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆