Skip to content Skip to sidebar Skip to footer

How To Exclude All Title With Find?

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

Solution 1:

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 find

def TermFind(Title):
    terms=['Arcserve','OLP NL','LicSAPk','Symantec']
    disc=False
    forvalin terms:
        if Title.find(val)!=-1:
            disc=True
            breakreturn disc

When 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.

Solution 2:

A similar idea using any

import requests 
from bs4 import BeautifulSoup

url = 'https://www.cdsoft.co.il/index.php?id_product=300610&controller=product'
html = requests.get(url)
bsObj = BeautifulSoup(html.content, 'lxml')
title = str ( bsObj.title ).replace ( '<title>', '' ).replace ( '</title>', '' )
items = ['Arcserve','OLP NL','LicSAPk','Symantec']

ifnotany(item in title for item in items):
    print(title)

Post a Comment for "How To Exclude All Title With Find?"