【问题标题】:beautifulsoup - obtaining the tag and it's parent from the text inside?beautifulsoup - 从里面的文本中获取标签和它的父级?
【发布时间】:2022-11-01 10:55:29
【问题描述】:

使用 beautifulsoup 可以执行以下操作:

for heading in soup.find_all('h1'):
   print(heading.text)

Top Rated Movies

但是,有没有一种方法可以在给定文本的情况下自行提取标签?从上面的示例向后工作的一种方式,例如:

soup.find_tag('Top Rated Movies')

h1

【问题讨论】:

    标签: python web-scraping beautifulsoup


    【解决方案1】:
    for tag in soup.findAll(True, text="Top Rated Movies"):
        print(tag.name)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 2022-09-23
      • 2017-04-25
      • 1970-01-01
      • 2021-07-22
      • 2021-07-26
      • 1970-01-01
      相关资源
      最近更新 更多