【问题标题】:findAll-beautifulsoup-python can not work properly [closed]findAll-beautifulsoup-python 无法正常工作 [关闭]
【发布时间】:2018-12-12 12:41:21
【问题描述】:

当我使用findAll 函数时,我遇到了一个问题。 findAll 功能无法正常工作,无法区分<td> 标签的结尾或找不到</td>。它将所有 html 代码放入我定义的 t1 变量中。 任何人都可以帮忙吗?我把它的输出放在这里。

t1 = soup.findAll('td',{'data': 'Text:'})
print('( Text:   ',t1.text,' )')

输出:

( Text:    helloworld  * , hello:  * . hiii * ;hello * ; </td>
      <td id="dtt" datetime="2018-12-06T19:08:56Z" data="Summary:">world hello</td>
      </tr>  

如果它工作正常,它应该给我们这个输出。

( Text:    helloworld  * , hello:  * . hiii * ;hello * ;  )

我还应该注意到,这对任何其他&lt;td&gt; 都适用,但对于这个&lt;td&gt; 我有问题。我认为*; 或末尾的空格有些问题。你有什么意见?

【问题讨论】:

标签: python python-3.x beautifulsoup


【解决方案1】:

您可以使用以下方法从脏输入中获得更清晰的解析结果:

    soup = bs4.BeautifulSoup(html, 'lxml-xml')

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 2016-07-30
    • 2014-06-13
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    相关资源
    最近更新 更多