from lxml import etree from get_weibo_content.process_data import remove_html_tags def get_like_count(html): selector = etree.HTML(html) weibo_like_count_temp = selector.xpath('//div[@class="card-act"]/ul/li[4]/a/em') weibo_like_count = [] for i in weibo_like_count_temp: temp = remove_html_tags(etree.tostring(i)) if temp: weibo_like_count.append(temp) else: weibo_like_count.append('0') return weibo_like_count