My bot uses Beautiful soup to parse HTML, and also prints out the web page title of a link said in IRC. This all works except for one thing: If someone gives a dead/fake link, the bot crashes.
The link grabber triggers when "http" is found, so for example if someone just said "http", it crashes because there's no response. Does anyone know how to fix this?
Here's the part of the code that grabs the link and get's the web page title and posts it:
msg_split = msg.split(' ')
for item in msg_split:
if re.search('^http.*', item, re.I):
link = item
if item.find(','):
link = link.replace(',', ' ')
soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(link))
link_title = soup.title.string
ircSend('PRIVMSG ' + args[2] + ' ' + link_title)