You are passing the whole Element
(<a href="...">
) around here. You forgot to assign the tag.get('href')
result:
for tag in soup.find_all('a'):
link = tag.get('href')
if 'http://t.co/' in link:
webbrowser.open_new_tab(link)
You can simplify your loop a little by using a regular expression match:
import re
for tag in soup.find_all('a', href=re.compile('^http://t\.co/')):
link = tag['href']
webbrowser.open_new_tab(link)