赞
踩
‘详情页’])
csv_writer.writeheader()
for page in range(1, 26):
print(f’正在保存第{page}页数据内容===========')
url = f’http://bang.dangdang.com/books/bestsellers/01.00.00.00.00.00-year-2017-0-1-{page}’
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36’
}
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,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。