Home > Enterprise >  Get specifc element with BeautifulSoup
Get specifc element with BeautifulSoup

Time:06-13

So, I have this html structure in a bs4.BeautifulSoup:

<div >
  <a href="#"  role="button" aria-label="Adicionar Central Multimídia Pósitron SP8730DTV LCD 6,2&amp;quot; TV Entrada para Câmera de Ré USB Bluetooth aos favoritos">
   <i  alt="icon_wishlist" aria-hidden="true">

And I need to get the aria-label :

"Adicionar Central Multimídia Pósitron SP8730DTV LCD 6,2&amp;quot; TV Entrada para Câmera de Ré USB Bluetooth aos favoritos"

Looks like an easy task, but I tried everthing and nothing works. I don't even need to get the exact text, if the phrase is inside some text i can use regex to retrieve what I want..

Some exemples of what I tried:

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'}) 

CodePudding user response:

Thanks for the answers, but my problem was that the element really wasn't appearing. Since I was using selenium, the default windows size caused the problem, because the element that I needed only appear with a wider windows.

adding the argument:

op.add_argument('window-size=1200,1100')

Solved my problem.

  • Related