i have function that get me all the titles from my website i dont want to get the title from some products is this the right way ? i dont want titles from products with the words "OLP NL" or "Arcserve" or "LicSAPk" or "symantec"
def get_title ( u ):
html = requests.get ( u )
bsObj = BeautifulSoup ( html.content, 'xml' )
title = str ( bsObj.title ).replace ( '<title>', '' ).replace ( '</title>',
'' )
if (title.find ( 'Arcserve' ) or title.find ( 'OLP NL' ) or title.find (
'LicSAPk' ) or title.find (
'Symantec' ) is not -1):
return 'null'
else:
return title
if (title != 'null'):
ws1 [ 'B1' ] = title
meta_desc = get_metaDesc ( u )
ws1 [ 'C1' ] = meta_desc
meta_keyWrds = get_metaKeyWrds ( u )
ws1 [ 'D1' ] = meta_keyWrds
print ( "writing product no." + str ( i ) )
else:
print("skipped product no. " + str ( i ))
continue;
the problem is that the program exclude all my products and all i'm seeing is "skipped product no." ? whay ? not all of them have these words ...
You can change the if statement for
(title.find ( 'Arcserve' )!=-1 or title.find ( 'OLP NL' )!=-1 or title.find ('LicSAPk' )!=-1 or title.find ('Symantec' )!=-1)
or you can create a function to evaluate the terms that you want to findWhen I used the if statement always returned True regardless of the title value. I couldn't find an explanation for such behavior, but you can try checking this [Python != operation vs "is not" and [nested "and/or" if statements. Hope it helps.
A similar idea using
any