html_parser里面的parse的return值順序問題
正確的:
def parse(self, url, content):
? ? print 'parse'
? ? if url is None or content is None:
? ? ? ? return
? ? soup = BeautifulSoup(content, 'html.parser', from_encoding = 'utf-8')
? ? new_data = self._get_new_data(url, soup)
? ? new_urls = self._get_new_urls(url, soup)
? ? return ?new_urls, new_data
錯(cuò)誤的:
def parse(self, url, content):
? ? print 'parse'
? ? if url is None or content is None:
? ? ? ? return
? ? soup = BeautifulSoup(content, 'html.parser', from_encoding = 'utf-8')
? ? new_data = self._get_new_data(url, soup)
? ? new_urls = self._get_new_urls(url, soup)
? ? return ?new_data, new_urls
在試驗(yàn)過程中,發(fā)現(xiàn)錯(cuò)誤是最后的return順序弄反導(dǎo)致的,導(dǎo)致的錯(cuò)誤代碼是:
TypeError: 'set' object has no attribute '__getitem__'
用的pycharm 4.5.3,python 2.7.12.
謝謝老師~~