用BeautifulSoup(re.text, lxml),关于beautifulsoup 与 lxml 的问题
import requests from bs4 import BeautifulSoup import re sum = 0 r = requests.get('https://book.douban.com/subject/5299764/comments/') soup = BeautifulSoup(r.text, 'lxml') pattern = soup.find_all('p','comment-content') for item in pattern: print(item.string) pattern_s = re.compile('<span class="user-stars allstar(.*?) rating"') p = re.findall(pattern_s, r.text) for star in p: sum += int(star) print(sum)
在运行时,出错,与lxml有关
求大神,帮忙