# -*- coding:utf-8 -*-"""
爬取《三十六骑》豆瓣上第一页短评内容和平均打分
@author:Cbright
"""import requests as req
from bs4 import BeautifulSoup
import re
sum=0
r = req.get('https://book.douban.com/subject/30257985/comments/')
soup = BeautifulSoup(r.text,'lxml')
comments = soup.find_all('span','short')for item in comments:print(item.string)
stars = re.compile('<span class="user-stars allstar(.*?).rating"')
p = re.findall(stars,r.text)for star in p:sum=sum+int(star)print(sum/len(p)/10)