search

Home  >  Q&A  >  body text

python - BeautifulSoup4的问题

BeautifulSoup可以获取到页面中display为none的元素么

PHP中文网PHP中文网2810 days ago292

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-18 09:36:25

    If display:none is specified with style in html, it can be obtained with BeautifulSoup.

    print soup1.select( '[style~="display:none"]' )
    

    Documentation: select method used CSS2 selectors: http://www.crummy.com/softwar...

    However, the display:none in the page may also come from CSS rendering, or attributes dynamically added by js. In this case, these elements cannot be obtained using BeautifulSoup alone. You need to use selenium to parse it first, and then use BeautifulSoup to obtain it.

    reply
    0
  • Cancelreply