【问题标题】:Difference between text and string in BeautifulSoup [duplicate]BeautifulSoup中文本和字符串之间的区别[重复]
【发布时间】:2016-07-14 08:58:55
【问题描述】:

当我在 BeautifulSoup 中搜索包含特定文本的标签时,我使用 find_all(string='text I want'):

soup = BeautifulSoup('<a id="someid">stackoverflow</a>', 'lxml')
soup.find_all(string='stackoverflow')

但我最近发现我可以这样做

soup.find_all(text='stackoverflow')

我查看了 BeautifulSoup 4 的 documentation,但在 find_all 上找不到任何带有文本参数的线索。

有什么不同吗?

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    来自docs

    使用字符串,您可以搜索字符串而不是标签。 字符串参数是 Beautiful Soup 4.4.0 中的新参数。在早期版本中,它被称为文本。

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 2014-06-17
      • 2011-05-30
      相关资源
      最近更新 更多