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
错误的:
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
在试验过程中,发现错误是最后的return顺序弄反导致的,导致的错误代码是:
TypeError: 'set' object has no attribute '__getitem__'
用的pycharm 4.5.3,python 2.7.12.
谢谢老师~~