---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9620/2324248033.py in <module>
7 for num in range(start, finish):
8 print(f"Checking {num}...")
----> 9 num_status = check_seatNumber(num)
10 if not num_status: print(f'{num} is valid')
11 else: print(f'{num} is invalid')
~\AppData\Local\Temp/ipykernel_9620/948570639.py in check_seatNumber(seatNumber)
2 response = requestSeatNumber(seatNumber)
3 soup = BeautifulSoup(response.content)
----> 4 sent = soup.find('p',attrs={'style':"font-size: 14px;color: red; margin-top: 11px;"}).text==''
5 print(sent)
6
AttributeError: 'NoneType' object has no attribute 'text'
長時間運行我的代碼后出現此錯誤幫助我解決它
def check_seatNumber(seatNumber): response = requestSeatNumber(seatNumber) soup = BeautifulSoup(response.content) sent = soup.find('p',attrs={'style':"font-size: 14px;color: red; margin-頂部:11px;"}).text=='' 列印(發送)
if (soup.find('p',attrs={'style':"font-size: 14px;color: red; margin-top: 11px;"}).text==''):
#getStudentInfo()
student_inform(soup)
else: return seatNumber
uj5u.com熱心網友回復:
soup.find()可以回傳None,并且該NoneType物件沒有text屬性。您可以通過拆分soup.find(...).text為以下內容來解決此問題:
found = soup.find('p',attrs={'style':"font-size: 14px;color: red; margin-top: 11px;"})
if found:
text = found.text
# Check text
在這里,如果found是None,則不輸入該if陳述句并且不會引發錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/530066.html
上一篇:在VisualStudio中查找與現有SSIS包相關的SQLServer作業
下一篇:在兩個事件之間波動
