2 回答

TA貢獻1871條經驗 獲得超13個贊
您可以更改 if 語句,(title.find ( 'Arcserve' )!=-1 or title.find ( 'OLP NL' )!=-1 or title.find ('LicSAPk' )!=-1 or title.find ('Symantec' )!=-1)也可以創建一個函數來評估要查找的術語
def TermFind(Title):
terms=['Arcserve','OLP NL','LicSAPk','Symantec']
disc=False
for val in terms:
if Title.find(val)!=-1:
disc=True
break
return disc
當我使用 if 語句時,無論標題值如何,總是返回 True。我找不到這種行為的解釋,但是您可以嘗試檢查此 [ Python != operation vs "is not" 和 [ nested "and/or" if statements。希望能幫助到你。

TA貢獻1993條經驗 獲得超6個贊
類似的想法使用 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']
if not any(item in title for item in items):
print(title)
添加回答
舉報