[問題] BeautifulSoup select class filter

看板Python作者 (coco)時間8年前 (2017/07/01 15:59), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
<a class="heading__name" href=... <a class="heading__name hide" href=... 有兩種class,只想要filter拿到第一種結果"heading__name" 我的方法是soup.select(".heading__name") 結果第二種class也會包含在內, 如何正確拿到想要的結果? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.173.19.224 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1498924750.A.E82.html

07/02 00:46, , 1F
soup.select("a[class=heading__name]") 改這樣試試看
07/02 00:46, 1F

07/02 05:13, , 2F
可以唷 thank you
07/02 05:13, 2F

07/05 00:57, , 3F
或者 .heading__name:not(.hide)
07/05 00:57, 3F
文章代碼(AID): #1PLyREw2 (Python)