def get_post_from_response_part(post_html_element): #получаем информацию о идентификаторе, авторе, дате создания, содержимом поста #и комментариев к нему post_id = post_html_element.attrib["id"].replace('post-','') post_table = post_html_element.cssselect('table.post_table')[0] post_author_img_url = post_table.cssselect('tr td.image img')[0].attrib['src'] post_author_name = post_table.cssselect('tr td.info a.author')[0].text_content() post_author = PostAuthor( post_author_name, post_author_img_url ) post_date = post_table.cssselect('tr td.info span.rel_date')[0].text_content() post_text_elem = post_table.cssselect('tr td.info div.wall_post_text')[0] if post_text_elem.cssselect('span'): post_text_elem = post_text_elem.cssselect('span')[1] post_text_lines = [] for line in post_text_elem.itertext(): post_text_lines.append(line) post_text = '\n'.join(post_text_lines) post_info = PostInfo( post_id, post_author, post_date, post_text ) replies = post_table.cssselect('div.replies_wrap')[0] #поиск кнопки с доп раскрывающимся списком комментов has_more_comments = replies.cssselect( 'div.wrh_text' ) if has_more_comments: post_info.hidden_replies_info = has_more_comments[0].text_content() return post_info
def get_hidden_comments(post_id): """ Возвращает набор скрытых комментов для указанного поста. Это тоже надо бы закешировать. """ url = PostInfo.hidden_comments_url(post_id) comments = VkontakteGroupNewsReader.get_hidden_comments(url) return comments