赞
踩
response = requests.get(url=url, headers=headers)
selector = parsel.Selector(response.text)
lis = selector.css(‘.bang_list_mode li’)
for li in lis:
title = li.css(‘.name a::attr(title)’).get() # 标题/书名
recommend = li.css(‘.tuijian::text’).get() # 推荐
star = li.css(‘.star a::text’).get() # 评价
author = li.css(‘div:nth-child(5) a:nth-child(1)::attr(title)’).get() # 作者
date = li.css(‘div:nth-child(6) span::text’).get() # 出版日期
press = li.css(‘div:nth-child(6) a::text’).get() # 出版社
price_r = li.css(‘.price .price_r::text’).get() # 原价
price_n = li.css(‘.price .price_n::text’).get() # 售价
price_e = li.css(‘.price_e span::text’).get() # 电子书价格
href = li.css(‘.name a::attr(href)’).get() # 详情页
dit = {
‘标题’: title,
‘推荐’: recommend,
‘评价’: star,
‘作者’: author,
‘出版日期’: date,
‘出版社’: press,
‘原价’: price_r,
‘售价’: price_n,
‘电子书价格’: price_e,
‘详情页’: href,
}
csv_writer.writerow(dit)
print(title, recommend, star, author, date, press, price_r, price_n, price_e, sep=’ | ')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。