NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
Posted thedatadigger
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.相关的知识,希望对你有一定的参考价值。
soup=BeautifulSoup(html.text,‘lxml‘) #data=soup.select(‘body > div.main > div.ctr > div > div.newsmcont > p:nth-of-type(3) > img‘)
#data=soup.select(‘body > div.main > div.ctr > div > div.newsmcont > p > img‘)[2]
data=soup.select(‘body > div.main > div.ctr > div > div.newsmcont > p:nth-child(3) > img‘)
print(data)
当使用copy selector时,复制的是nth-child,而soup 似乎不支持nth-child,所以会报以下错误:
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
将nth-child 改为 nth-of-type 就可以了。
或者去掉nth-child,在后面加上[i-1],即[2]。
关于nth-child 和 nth-type,他们都是取父元素下的第n个元素,他们的区别可以通过下面这个例子了解一下:
<div> <ul class="demo"> <p>zero</p> <li>one</li> <li>two</li> </ul> </div>
上面这个例子,.demo li:nth-child(2)
选择的是<li>one</li>
节点,而.demo li:nth-of-type(2)
则选择的是<li>two</li>
节点。
以上是关于NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.的主要内容,如果未能解决你的问题,请参考以下文章
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
为啥返回 NotImplemented 而不是引发 NotImplementedError
kotlin.NotImplementedError: 操作未在 EditText 上使用 addTextChangedListenerher 实现