selecting second child in beautiful soup with soup.select?

后端 未结 3 903
你的背包
你的背包 2020-12-09 04:00

I have:

Names

John

Peter

now what\'s the easiest way to get the Pet

3条回答
  •  没有蜡笔的小新
    2020-12-09 04:35

    'nth-of-child' is simply not implemented in beautifulsoup4 (at time of writing), there is simply no code in the beautifulsoup codebase to do it. The authors explicitly added the 'NotImplementedError' to explain this, here is the code

    Given the html you quote in your question you are not looking for a child of h2#names.

    What you are really looking for is the second adjacent sibling, I'm not a css selector guru but I found that this worked.

    soup.select("#names + p + p")
    

提交回复
热议问题