【问题标题】:How to write div class attribute BeaufitulSoupdiv类属性BeautifulSoup怎么写
【发布时间】:2018-01-27 01:54:16
【问题描述】:

我知道用 python BeautifulSoup 写这样的新标签:

# create new_div
 new_div = soup.new_tag("div", id="description", style="float:left")
# insert it into the document
 soup.body.append(new_div)

但我在添加类属性时出错,语法无效:

new_div = soup.new_tag("div", class="description", style="float:left") ^ SyntaxError: 无效语法

创建新标签时如何添加类属性的正确方法?

谢谢

【问题讨论】:

标签: python beautifulsoup


【解决方案1】:

很抱歉,我是通过找到其他参考来写这篇文章的。 on stackoverflow question

new_div = soup.new_tag("div", style="float:left", **{'class':'classname'})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多