Home > database >  Scrape without tag in <a>
Scrape without tag in <a>

Time:09-29

I'm trying to scrape with python a site but i have a problem with text in tag without class or id

<div class="d-inline"> <img class="team-img" src="https://cdn.fifacm.com/content/media/imgs/fifa22/teams/52/l73.png?v=10"> <a href="/22/team/73/paris-saint-germain"> Paris Saint-Germain </a> </div>

I need to extract "Paris Saint-Germain"

How could I do?

Thanks Bye

CodePudding user response:

Here is the solution:

Code:

from bs4 import BeautifulSoup

tag = """
<div class="d-inline">
 <img class="team-img" src="https://cdn.fifacm.com/content/media/imgs/fifa22/teams/52/l73.png?v=10"/>
 <a href="/22/team/73/paris-saint-germain">
  Paris Saint-Germain
 </a>
</div>

"""

soup = BeautifulSoup(tag, 'html.parser')


tag= soup.select_one('div.d-inline')
print(tag.text)

Output:

Paris Saint-Germain
  • Related