作者atb (Transition)
看板Python
標題[問題] BeautifulSoup如何排除特定class
時間Tue Feb 28 20:01:19 2023
各位好,最近使用beautifulsoup在爬html時遇到一個問題
<table class="alpha beta">
</table>
<table class="alpha">
</table>
若使用 beautifulsoup.select('table.alpha')會選到兩個table
但我不希望class="beta"的table被選到,請問要如何修正呢? 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.142.61.194 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1677585683.A.271.html
1F:→ Hsins: bs.select("table[class='alpha']") 02/28 22:17
2F:→ lycantrope: "table[class='alpha']" 02/28 23:14
3F:推 OnoderaHaru: s.select('.alpha:not(.beta)') 03/01 07:28
4F:→ tzouandy2818: Google搜尋CSS選擇器 03/02 06:57
5F:→ atb: 謝謝大家的協助,問題解決了,可以正確選取了 03/04 19:57
7F:→ g919233: css-selector/ 03/11 06:34