接下来咱们就来爬取豆瓣上评分最高的

250部电影

这次我们就要来使用上次说的

BeautifulSoup + Reuqests

进行爬取啦

这次

我们将爬取到的内容存放到 excel 吧

首先打开我们的目标链接

https://movie.douban.com/top250

可以看到这样一个网页

每一页显示了 25 条数据

当我们点击下一页的时候

链接请求参数变了

https://movie.douban.com/top250?start=25&filter=

我们一眼就看的出来

这里就是从第 25 条数据开始加载的

所以

我们可以使用这个 start=25 来做变量

实现翻页获取信息

接下来我们来看下我们要的主要信息

电影名称

电影图片

电影排名

电影评分

电影作者

电影简介

首先请求豆瓣网

def main(page):url = 'https://movie.douban.com/top250?start='+ str(page*25)+'&filter='html = request_douban(url)soup =  BeautifulSoup(html)
def request_douban(url):try:response = requests.get(url)if response.status_code == 200:return response.textexcept requests.RequestException:return None

然后根据服务器返回的请求响应,对其进行解析

def  save_to_excel(soup):for item in list:item_name = item.find(class_='title').stringitem_img = item.find('a').find('img').get('src')item_index = item.find('em').stringitem_score = item.find(class_='rating_num').stringitem_author = item.find('p').stringitem_intr = item.find(class_='inq').stringprint('爬取电影:' + item_index + ' | ' + item.name + ' | ' + item_score + ' | ' + item_intr)

整体代码如下:

#BeautifulSoup练习
from bs4 import BeautifulSoup
import requests, sys
import xlwt
import lxmldef request_douban(url):try:response = requests.get(url)if response.status_code == 200:return response.textexcept requests.RequestException:return None
def  save_to_excel(soup):book = xlwt.Workbook(encoding='utf-8',style_compression=0)list = soup.find(class_='grid_view').find_all('li')sheet = book.add_sheet('豆瓣电影Top250', cell_overwrite_ok=True)sheet.write(0, 0, '名称')sheet.write(0, 1, '图片')sheet.write(0, 2, '排名')sheet.write(0, 3, '评分')sheet.write(0, 4, '作者')sheet.write(0, 5, '简介')n = 1for item in list:item_name = item.find(class_='title').stringitem_img = item.find('a').find('img').get('src')item_index = item.find('em').stringitem_score = item.find(class_='rating_num').stringitem_author = item.find('p').textitem_intr = item.find(class_='inq').stringprint('爬取电影:' + item_index + ' | ' + item_name + ' | ' +item_author+' | ' + item_score + ' | ' + item_intr)sheet.write(n, 0, item_name)sheet.write(n, 1, item_img)sheet.write(n, 2, item_index)sheet.write(n, 3, item_score)sheet.write(n, 4, item_author)sheet.write(n, 5, item_intr)n = n+1print("n:"+str(n))book.save('豆瓣最受欢迎的250部电影.xlsx')def main(page):url = 'https://movie.douban.com/top250?start='+ str(page*25)+'&filter='html = request_douban(url)soup =  BeautifulSoup(html)save_to_excel(soup)# list = soup.find(class_='grid_view').find_all('li')if __name__ == '__main__':main(0)

爬取豆瓣最受欢迎的250部电影慢慢看相关推荐

  1. 史上最受欢迎的250部电影排行榜

    注明:文章来源于别人. 史上最受欢迎的250部电影排行榜(分享) 来源: 任振毅的日志 IMDB评选出的250部最佳电影,看看你看过多少部,又听说过多少部?如果整个榜单看下来你觉得大部分都没有听说过- ...

  2. python豆瓣历史评分_Python实战-爬取豆瓣top250评分高于指定值的电影信息

    思路 1. 要获得怎么样的数据 2. 找到数据来源 3. 模拟浏览器发送请求获得数据 4. 处理数据,保存数据 第一步: 在这里数据是豆瓣top250中高于指定分数的电影信息 信息有:名称,评分,格言 ...

  3. 爬取豆瓣电影 Top250 电影并存储到 Excel 表中

    文章目录 一.前期准备 二.代码 一.前期准备 观察网页 url 或者通过最下面的分页审查元素: 发现规律,0-25-50...递增,以此确定爬取 page 页码 确定爬取的内容 名称.图片.排名.评 ...

  4. python爬取豆瓣图书top250_「豆瓣读书250」爬取豆瓣TOP250书单 - seo实验室

    豆瓣读书250 小白学习爬虫 爬取豆瓣TOP250的书,正好本人也喜欢看书 思路分析: https://book.douban.com/top250这是TOP250第一页的链接 https://boo ...

  5. 爬取豆瓣TOP250书单

    小白学习爬虫 爬取豆瓣TOP250的书,正好本人也喜欢看书 思路分析: https://book.douban.com/top250这是TOP250第一页的链接 https://book.douban ...

  6. python爬虫——Cookie登录爬取豆瓣短评和影评及常见问题

    python爬虫--Cookie登录爬取豆瓣短评和影评 常见问题(本文已解决) 具体步骤 一.获取网页源码 短评.影评 二.解析网页源码及爬取评论 1.短评网页解析 ①确定位置 2.短评爬取 ①名称爬 ...

  7. Scrapy 实例——爬取豆瓣图书排名top250

    1.安装 pip install E:\python\lxml-4.2.6-cp36-cp36m-win_amd64.whl pip install E:\python\Twisted-18.9.0- ...

  8. 爬虫练习(1)-- 爬取豆瓣最新电影

    准备工作 本次爬取的移动手机端的接口.我们可以使用 Google 浏览器自带的调试模式去做切换.可能会出现切换了手机模式,只是变成了一个手机浏览器的形式,不是真正的 移动端接口.一种解决方案是先切换为 ...

  9. requests爬取豆瓣前250部高分电影

    这两天又写了一个爬取豆瓣前250部高分电影的爬虫,并把电影名字和图片保存到本地. 用的是requests和BeautifulSoup. @requires_authorization import r ...

最新文章

  1. jconsole工具使用----jvm内存泄漏问题
  2. php 接口继承,PHP面向对象之旅:接口的继承
  3. 在JAX-RS中使用@Context [第1部分]
  4. 数据查询和业务流分开_传统数仓和大数据数仓的区别是什么?
  5. 前端学习(2846):css浮动和定位布局
  6. 【CodeVS3372】选学霸
  7. JDBC和MySQL的实现原理
  8. 全景图航拍的方法,制作航拍全景图的步骤
  9. 第六章-网络可靠性设计
  10. latex系列---Latex参考文献的引用
  11. 实体门店营销,抽奖系统为何独占鳌头
  12. Doctrine 查询语法
  13. 人脸检测技术现状及3D检测调研
  14. 2019年CS224N课程笔记-Lecture 12: Subword Models
  15. dba怎么报考_深圳dba双证报考时间
  16. 超火的数码产品犀牛rhino模型素材网站合集看过来
  17. 媒体格式有几种,媒体格式的异同
  18. STM32之HAL库的Bootloader跳转到APP
  19. 信息系统成本与质量管理
  20. android11 定位权限页面不显示始终允许

热门文章

  1. [coreldraw X4]如何调节透明度
  2. 苹果手机锁屏密码忘了怎么办?在家也能搞定,赶紧收藏!
  3. RoHS 2.0标准十项有害物质管控范围
  4. 下一个颠覆的领域:区块链如何影响审计行业?(上)
  5. 1.6 Java遍历Map集合
  6. React-router4简约教程
  7. Kotlin-简约之美-进阶篇(三):Lambda的使用详解
  8. html5 求最大公约数和最小公倍数
  9. uni-app葵花宝典(欲练此功,必先自宫)
  10. 50家公司Java,C++招聘要求