Search code examples
pythonhtmlweb-scrapingbeautifulsouptags

Web-scraping a-tag nested inside div-tag


I just want to extract all the five a-tag data list of card which is nested the div tag as shown in the picture. How could I extract it?

HTML CODE

I have tried this one,

btag = []
for data in soup.find_all('div', id="mosaic-provider-jobcards"):
  for atag in data:
     atag = soup.find_all('a').append(btag)

print(btag)

but it showed none. Can anyone help?


Solution

  • You can use CSS selectors:

    soup.select('#mosaic-provider-jobcards > a')
    

    https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors