这是错误:maximum recursion depth exceeded while calling a Python object我正在使用beautifulsoup解析从中接收到的网页 HTML,requests然后将解析后的数据存储到Product类中。该函数通过从 调用一个线程来运行ThreadPoolExecutor()。运行功能: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贡献1875条经验 获得超5个赞
你在这里进入无限递归:
@property
def title(self):
return self.title
返回self.title与再次调用此函数相同,因为定义一个名为的函数title会覆盖变量self.title。
这也是无限递归:
@title.setter
def title(self, title):
self.title = title
@title.setter将重新定义赋值,比如从这个函数self.title = title中调用。self.title.setter(title)
对于和 也是一样self.price的。self.price_stringself.asin
要解决此问题,请重命名您的变量:
def __init__(...):
self._title = None
@property
def title(self):
return self._title
添加回答
举报
0/150
提交
取消