from lxml import etreeimport requestsHEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36','Referer': 'http://www.dytt8.net/html/gndy/dyzz/list_23_1.html'}text = response.text#text=response.content.decode("gbk")html=etree.HTML(text)detail_urls=html.xpath("//table[@class='tbspan']//a/@href")
json保存
movies = []for li in all_li:movie = {}title = li['data-title']movie['title'] = titlemovies.append(movie)with open('douban.json','w',encoding='utf-8') as fp:json.dump(movies,fp,ensure_ascii=False)
