I have a code like this...
if active == 1: // A flag which is set if a Site is Active
for link in BeautifulSoup(content, parseOnlyThese=SoupStrainer('a')):
if link.has_key('href'):
if 'MY_TEXT' in link['href'].upper(): //Check if the link has the string MY_TEXT in it. If it has print it and break the loop
print link['href']
break
Now, I want to improvize this code to check MY_TEXT1, MY_TEXT2 and MY_TEXT3 too. I do not want to write plenty of IF statements. Instead I did something like this
a = ['MY_TEXT1', 'MY_TEXT2', 'MY_TEXT3']
if active == 1: // A flag which is set if a Site is Active
for link in BeautifulSoup(content, parseOnlyThese=SoupStrainer('a')):
if link.has_key('href'):
for x in a:
if link['href'].__contains__(x):
print link['href']
break
But this did not work. I mean no Syntax/Compile/Run-time error. No output either. What am I doing wrong?
if x in link['href'].upper()as before?