【问题标题】:Python: search for html tag starting with characters [duplicate]Python:搜索以字符开头的html标签[重复]
【发布时间】:2017-06-29 15:15:32
【问题描述】:

我正在使用以下代码来查找具有“产品类别”类的标签。

soup0.findAll("a",{"class":"product-category"})

如果我需要找到一个类以product-category 开头的标签,我该怎么写。 我尝试使用

soup0.findAll("a",{"class":%"product-category"}) ##This doesnt work.

有什么办法吗?

谢谢,

【问题讨论】:

    标签: python html web web-scraping beautifulsoup


    【解决方案1】:

    从文档中,您可以执行以下操作:

    import re
    tagsStartingWithB = soup.findAll(re.compile('^b'))
    [tag.name for tag in tagsStartingWithB]
    # [u'body', u'b', u'b']
    

    查看更多here.

    【讨论】:

      猜你喜欢
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2017-01-08
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      相关资源
      最近更新 更多