【问题标题】:Escaping "[" in css selector beatifulsoup python在css选择器beautifulsoup python中转义“[”
【发布时间】:2018-02-21 13:05:53
【问题描述】:

这是我的输入:

input autocomplete="off" id="one-step-full-name" name="user[name]"

当我尝试时:

BeautifulSoup.select('input[name=user\[name\]]')

我明白了:

lib\site-packages\bs4\element.py", line 1477, in select 'Unsupported or invalid CSS selector: "%s"' % token) ValueError: Unsupported or invalid CSS selector: "input[name=user[name]]"

BeatifulSoup 4.6.0 版

转义有什么问题?

【问题讨论】:

  • 不熟悉 BeautifulSoup,但您可以尝试使用违规字符的十六进制代码进行转义。 'input[name=user\5Bname\5D]'

标签: python css beautifulsoup escaping selector


【解决方案1】:

在element.py的606行:

r'=?"?(?P<value>[^\]"]*)"?\]$'

右括号符号(])不能存在于双引号("")中。

你可以试试:

'input[name*=\\"user\[name]'

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 2018-08-19
    • 1970-01-01
    • 2012-01-17
    • 2014-10-22
    • 2016-04-05
    • 2016-03-31
    • 2012-01-07
    • 2017-01-23
    相关资源
    最近更新 更多