0

I have the following HTML

<div class="ui_columns is-gapless is-mobile">
    <div class="ui_column is-4 providerLogoOuter">
        <span class="providerLogoInner" title=""><imgsrc="https://static.tacdn.com/img2/branding/hotels/Hoteiscom_384x164.png" class="providerImg" alt="Hoteis.com">

But I need to get only the "Hoteis.com" from the alt=

I am trying to get it using BeautifulSoap, but how can I get this element?

name_player = soup.find_all(class_='providerLogoInner')[0]

It Returns no elements

2 Answers 2

1

Is that malformed html or a typo?

html="""
<div class="ui_columns is-gapless is-mobile">
<div class="ui_column is-4 providerLogoOuter">
<span class="providerLogoInner" title=""><imgsrc="https://static.tacdn.com/img2/branding/hotels/Hoteiscom_384x164.png" class="providerImg" alt="Hoteis.com">
"""
from bs4 import BeautifulSoup
soup=BeautifulSoup(html,'html5lib')
print(soup.find(class_='providerImg')['alt'])

Output:

Hoteis.com
Sign up to request clarification or add additional context in comments.

Comments

1

You can do:

from bs4 import BeautifulSoup


raw = '''
<div class="ui_columns is-gapless is-mobile">
    <div class="ui_column is-4 providerLogoOuter">
        <span class="providerLogoInner" title=""><imgsrc="https://static.tacdn.com/img2/branding/hotels/Hoteiscom_384x164.png" class="providerImg" alt="Hoteis.com">
'''

soup = BeautifulSoup(raw,'html5lib')

hotel_lnk = soup.find('span',{'class':'providerLogoInner'}).next['alt']

print(hotel_lnk)

#'Hoteis.com'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.