defparse_single_html(html):"""
解析单个HTML,需要返回目标数据。即是:title,source,time,link
"""# 定义几个空列表和一个空字典来装
titles =[]
links =[]
sources =[]
times =[]
data_crew =[]
html = etree.HTML(html)
results = html.xpath(".//div[@class='left_list_box']/h1/a[@class='title']")for result in results:
title = result.get('title')# title
link = result.get('href')# link
source = html.xpath(".//div[@class='banquan']/span/text()")[0]# source
time = html.xpath(".//div[@class='banquan']/span/text()")[1]# linkprint(time)
data ={'titles':title,'links':link,'sources':source,'times':time}
data_crew.append(data)return data_crew
all_datas =[]for html in htmls:print('=='*30)
all_datas.extend(parse_single_html(html))