判断是否存在空值
from bs4 import *
import requests
head = {'user-agent':'betbargain/android-7.0/0.0.5'}
amaurl = input('Enter amazon url')
amazinfo = requests.get(amaurl,headers=head)
amasoup = BeautifulSoup(amazinfo.text,'lxml')
findResult = amasoup.find("span", attrs={"id":'productTitle'})
amatit = ""
if (findResult != None): # Added a check for findResult being None
amatit = str(findResult).strip() # Changed .string to str()
print(amatit)