Heim  >  Fragen und Antworten  >  Hauptteil

python - BeautifulSoup4的问题

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

PHP中文网PHP中文网2741 Tage vor271

Antworte allen(1)Ich werde antworten

  • PHPz

    PHPz2017-04-18 09:36:25

    如果 display:none 在 html 中用 style 指定,那么可以用 BeautifulSoup 获取。

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

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

    不过页面中 display:none 还可能来自CSS渲染,或者 js 动态添加的属性,针对这种情况,只用 BeautifulSoup 无法获取这些元素。需要先用 selenium 进行解析,然后再用BeautifulSoup获取。

    Antwort
    0
  • StornierenAntwort