所以,我在 bs4.BeautifulSoup 中有這個 html 結構:
<div class="bordered radius border-color-ui-2 bg-white h-100">
<a href="#" class="box-card-link-wishlist" role="button" aria-label="Adicionar Central Multimídia Pósitron SP8730DTV LCD 6,2&quot; TV Entrada para Camera de Ré USB Bluetooth aos favoritos">
<i class="icon icon_wishlist txt-body-lg pointer r-0 t-0 card-wishlist pos-absolute" alt="icon_wishlist" aria-hidden="true">
我需要得到 aria-label :
"Adicionar Central Multimídia Pósitron SP8730DTV LCD 6,2&quot; TV Entrada para Camera de Ré USB Bluetooth aos favoritos"
看起來很容易,但我嘗試了一切,但沒有任何效果。我什至不需要獲取確切的文本,如果短語在某些文本中,我可以使用正則運算式來檢索我想要的內容..
我嘗試過的一些例子:
names = bs.find_all('div'{'class':'bordered radius border-color-ui-2 bg-white h-100'})
names = bs.find_all('div'{'class':'box-card-link-wishlist'})
names = bs.find_all('a'})
names = bs.find_all('a',href = True})
names = bs.select('a[aria-label]')
names = bs.find_all('button'})
uj5u.com熱心網友回復:
感謝您的回答,但我的問題是該元素確實沒有出現。由于我使用的是 selenium,因此默認視窗大小會導致問題,因為我需要的元素只出現在更寬的視窗中。
添加引數:
op.add_argument('window-size=1200,1100')
解決了我的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/489831.html
