我如何在带有bs4的python中获取带有连字符的标签的值?

我在学校项目中使用模块bs4的python,但我有一个问题。我想从标签获取一个值,但是此标签包含破折号(-)。我不知道。显然,我收到语法错误:

SyntaxError:关键字不能是表达式
...
...
print(papers[0].find("a", abc-xyz = True)["abc-xyz"])

请你帮助我好吗?

非常感谢! 注意安全!

评论
  • 好菇凉
    好菇凉 回复

    abc and xyz in your code are being used expression (subtraction) and being set to True, which is wrong.

    And then you're trying to locate "abc-xyz".

    All you have to do is fix abc-xyz = True with proper attributes. Check out documentation.

  • 初吻给了烟
    初吻给了烟 回复

    我敢打赌,您正在寻找看起来像这样的标签

    <a abc-xyz="True" href="http://www.example.com">
    

    如果我是对的,那么你想要

    the_tag = .find("a", {"abc-xyz" : True})
    value_of_abc_xyz = the_tag['abc-xyz']