Git Product home page Git Product logo

douban-spider's Introduction

豆瓣电影爬虫

使用

  • 创建s数据库
    • db.sql
  • 安装依赖
    • pip install -r requirements.txtpipenv install
  • 执行脚本
    • python main.py

思路

  • 调用接口获取全部标签信息,加入标签队列
  • 通过标签队列取出一个标签,爬取该标签下全部电影ID、标题等信息加入电影ID队列
  • 电影ID队列取出电影ID,详情页抓取详情,加入存储队列
  • 存储队列取出电影详情,存入MySQL

三个线程并发执行任务提高采集效率

程序结构图

程序结构图

涉及技术点

  • requests 请求
  • BeautifulSoup 使用 lxml 解析, 解析速度更快,容错率更高
  • 使用 CSS 选择器 选择数据,方便易用
  • 采用 多线程 并发爬取,加快爬取速度
  • 采用 多队列 传递信息,提高并发执行效率
  • 使用 random 处理缺失数据
  • 启动前检查已爬取电影,可断点续传

反爬策略

  • 采用 fake_useragent 随机生成 UA
  • 爬取时休眠 6~8 秒防止请求过快

douban-spider's People

Contributors

imyhui avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.