I see. Well one solution that comes to my mind is using a method from standard library: string.startswith()For example:

for link in soup.find("tag2").find("tag3").a['href']: if link.startswith("https://www.youtube.com") #Or if you want to exclude links you can pass to those that start with... string+=str(link) else: pass