[問題] BeautifulSoup如何排除特定class

看板Python作者 (Transition)時間1年前 (2023/02/28 20:01), 編輯推噓2(205)
留言7則, 6人參與, 1年前最新討論串1/1
各位好,最近使用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://www.ptt.cc/bbs/Python/M.1677585683.A.271.html

02/28 22:17, 1年前 , 1F
bs.select("table[class='alpha']")
02/28 22:17, 1F

02/28 23:14, 1年前 , 2F
"table[class='alpha']"
02/28 23:14, 2F

03/01 07:28, 1年前 , 3F
s.select('.alpha:not(.beta)')
03/01 07:28, 3F

03/02 06:57, 1年前 , 4F
Google搜尋CSS選擇器
03/02 06:57, 4F

03/04 19:57, 1年前 , 5F
謝謝大家的協助,問題解決了,可以正確選取了
03/04 19:57, 5F

03/11 06:34, 1年前 , 6F
03/11 06:34, 6F

03/11 06:34, 1年前 , 7F
css-selector/
03/11 06:34, 7F
文章代碼(AID): #1Z_UqJ9n (Python)
文章代碼(AID): #1Z_UqJ9n (Python)