ibeautiful
2022-11-29 14:52:40
這是錯誤:maximum recursion depth exceeded while calling a Python object我正在使用beautifulsoup解析從中接收到的網(wǎng)頁 HTML,requests然后將解析后的數(shù)據(jù)存儲到Product類中。該函數(shù)通過從 調(diào)用一個線程來運(yùn)行ThreadPoolExecutor()。運(yùn)行功能:executor = ThreadPoolExecutor()t2 = executor.submit(ScrapePageFull, PageHtml)product = t2.result()ScrapePageFull功能:def ScrapePageFull(data):soup = BeautifulSoup(data)product = Product()# Priceprice = soup.find(DIV, {ID: DATA_METRICS})[ASIN_PRICE]product.price = float(price)# ASINASIN = soup.find(DIV, {ID: DATA_METRICS})[ASIN_ASIN]product.asin = ASIN# Titletitle = soup.find(META, {NAME: TITLE})[CONTENT]product.title = title# Price Stringprice_string = soup.find(SPAN, {ID: PRICE_BLOCK}).textproduct.price_string = price_stringreturn product這是Product課程:class Product:def __init__(self): self.title = None self.price = None self.price_string = None self.asin = None pass# Getters@propertydef title(self): return self.title@propertydef price(self): return self.price@propertydef asin(self): return self.asin@propertydef price_string(self): return self.price_string# Setters@title.setterdef title(self, title): self.title = title@price.setterdef price(self, price): self.price = price@asin.setterdef asin(self, asin): self.asin = asin@price_string.setterdef price_string(self, price_string): self.price_string = price_string感謝您的幫助,謝謝。
1 回答

慕田峪4524236
TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個贊
你在這里進(jìn)入無限遞歸:
@property
def title(self):
return self.title
返回self.title與再次調(diào)用此函數(shù)相同,因?yàn)槎x一個名為的函數(shù)title會覆蓋變量self.title。
這也是無限遞歸:
@title.setter
def title(self, title):
self.title = title
@title.setter將重新定義賦值,比如從這個函數(shù)self.title = title中調(diào)用。self.title.setter(title)
對于和 也是一樣self.price的。self.price_stringself.asin
要解決此問題,請重命名您的變量:
def __init__(...):
self._title = None
@property
def title(self):
return self._title
添加回答
舉報(bào)
0/150
提交
取消