2017-09-13 69 views
2

这是我输入:转义 “[” 在CSS选择beatifulsoup蟒蛇

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

逃跑有什么问题?

+1

不熟悉BeautifulSoup,但你可以尝试与违规字符的十六进制代码逃逸。 ' '输入[名称=用户\ 5Bname \ 5D]'' –

回答

1

在606行中的element.py:

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

右括号符号(])不能在双引号( “”)存在。

你可以试试:

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