相关疑难解决方法(0)

在BeautifulSoup CSS选择器中处理冒号

输入HTML:

<div style="display: flex">
    <div class="half" style="font-size: 0.8em;width: 33%;"> apple </div>
    <div class="half" style="font-size: 0.8em;text-align: center;width: 28%;"> peach </div>
    <div class="half" style="font-size: 0.8em;text-align: right;width: 33%;" title="nofruit"> cucumber </div>
</div>
Run Code Online (Sandbox Code Playgroud)

所需的输出:所有div元素正好在下面<div style="display: flex">.

我正在尝试div使用CSS选择器找到父级:

div[style="display: flex"]
Run Code Online (Sandbox Code Playgroud)

这会引发错误:

>>> soup.select('div[style="display: flex"]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/.virtualenvs/so/lib/python2.7/site-packages/bs4/element.py", line 1400, in select
    'Only the following pseudo-classes are implemented: nth-of-type.')
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type. …
Run Code Online (Sandbox Code Playgroud)

html python beautifulsoup css-selectors html-parsing

6
推荐指数
1
解决办法
1340
查看次数