How to find all anchor labels inside a div using Beautifulsoup in Python

So here is what my HTML looks like, what I understand. This is all inside the table and repeated several times, and I just want the attribute value to hrefbe inside the div with the attribute class="Special_Div_Name". All these divs are inside the rows of the table and there are many rows.

<tr>
   <div class="Special_Div_Name">
      <a href="something.mp3">text</a>
   </div>
</tr>

I want only attributes hrefthat end in ".mp3" that are inside the div with the attribute class="Special_Div_Name".

So far I have managed to find this code:

download = soup.find_all('a', href = re.compile('.mp3'))
for text in download:
    hrefText = (text['href'])
    print hrefText

href , ".mp3" , , , . ".mp3" , div-.

+4
2

, :

special_divs = soup.find_all('div',{'class':'Special_Div_Name'})
for text in special_divs:
    download = text.find_all('a', href = re.compile('\.mp3$'))
    for text in download:
        hrefText = (text['href'])
        print hrefText
+6

Beautiful Soup CSS .select(), [href$=".mp3"], a href, .mp3.

.Special_Div_Name, , :

for a in soup.select('div.Special_Div_Name a[href$=".mp3"]'):
    print (a['href'])

, a [href], div, div a[href]:

for a in soup.select('div a[href]'):
    print (a)

, , , Special_Div_Name, :

for div in soup.select('.Special_Div_Name'):
    for a in div.find_all('a', href = re.compile('\.mp3$')):
        print (a['href'])

re.compile('.mp3') re.compile('\.mp3$'), . . , $, ( ).

+5

Source: https://habr.com/ru/post/1629284/


All Articles