【问题标题】:how to check the tag name corresponds to specific tag in Python如何检查标签名称对应于Python中的特定标签
【发布时间】:2017-07-06 19:35:49
【问题描述】:

我正在通过它的所有标签解析 html 文件,当我遇到 body 标签时,我想执行一些字符串操作并将结果保存回 html 文件。当我尝试

if tag.name == 'body':
  // go inside the loop

if 循环本身没有得到处理。检查标签名称是否与body标签对应的正确方法是什么

【问题讨论】:

  • 你可以使用beautiful soup 模块,它是为解析web html而设计的

标签: python html python-2.7 python-3.x beautifulsoup


【解决方案1】:

使用 beautifulsoup 找到答案并想将其更新给其他人:Soup.body.name

【讨论】:

  • 如果标签在正文中,是的。否则soup.your_tag,比如:soup.headsoup.title,...
猜你喜欢
  • 1970-01-01
  • 2018-11-01
  • 2019-10-25
  • 2017-12-03
  • 2012-12-04
  • 1970-01-01
  • 2021-05-28
  • 1970-01-01
相关资源
最近更新 更多