def gen_item_comment(self, response):
comment = []
new_comment = {}
comments_data = []
rep_time_list = response.xpath('//div[@class="authi"]//em').extract()
for indexi, content in enumerate(response.xpath('//td[@class="t_f"]').extract()):
soup = BeautifulSoup(content, 'lxml')
if soup.find('div', class_='attach_nopermission') is not None:
soup.find('div', class_='attach_nopermission').clear()
[s.extract() for s in soup('script')] # remove script tag
c = StrClean.clean_unicode(soup.get_text())
comments_data.append({'content': c, 'reply_time': self.format_rep_date(rep_time_list[indexi])})
new_comment['url'] = response.url
new_comment['comments_data'] = comments_data
comment.append(new_comment)
return comment
评论列表
文章目录