把豆瓣网的数据爬取下来并存在excel表格中
import requests
from bs4 import BeautifulSoup
import pandas as pd
img_urls=[]
titles=[]
ratings=[]
authors=[]
details=[]
books=[]
url='https://book.douban.com/latest'
headers={
'User-Agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63"}
data = requests.get(url, headers=headers)
soup=BeautifulSoup(data.text,'lxml')
book_left=soup.find('ul',{
'class':'cover-col-4 clearfix'})
book_left=book_left.find_all('li')
book_right=soup.find('ul',{
'class':'cover-col-4 pl20 clearfix'})
book_right=book_right.find_all('li')
books=list(book_left)+list(book_right)
for book in books:
img_url=book.find_all('a')[0].find('img').get('src')
img_urls.append(img_url