I am using bs4 to scrape a website I have this piece of expression:
links = ['https://example.com/' + link['href'] for link in school.findAll('a')]
What I need is to add another condition that if link has href only than append it with links. Here is the normal code.
if link.has_attr('href'):
//append'
I have tried this but found no success
links = ['https://example.com/' + link['href'] if link.has_attr('href') for link in school.findAll('a')]
['https://example.com/' + link['href'] for link in school.findAll('a') if link.has_attr('href')]