9.python3实用编程技巧进阶(四)
4.1.如何读写csv数据 爬取豆瓣top250书籍 import requests import json import csv from bs4 import BeautifulSoup books = [] def book_name(url): res = requests.get(url) html = res.text soup = BeautifulSoup(html, 'html.parser') items = soup.find(class_="grid-16-8 clearfix").find(class_="indent").find_all('table') for i in items: book = [] title = i.find(class_="pl2").find('a') book.append('《' + title.text.replace(' ', '').replace('\n', '') + '》') star = i.find(class_="star clearfix").find(class_="rating_nums") book.append(star.text + '分') try: brief = i.find(class_="quote").find(class_="inq") except