Giter VIP home page Giter VIP logo

spider's Introduction

C++ 爬虫程序

项目描述

使用 C++ 编程语言,实现一个 爬虫程序,来对图片进行下载。

开发平台

Windows 10

流程介绍

在这里插入图片描述

  1. 先输入一个起始 URL 进入 URL 队列。

  2. 在当前路径下创建一个文件夹。

    #include <Windows.h>
    
    CreateDirectory("./images", NULL);
  3. 获取到当前队列中首部的 URL。

  4. 解析 URL,主要作用是判断是否是正确的 URL,并且获取到服务器域名和资源路径。

  5. 连接服务器。

    gethostbyname(std::string); // 通过这个函数获取到服务器的 IP 地址 
  6. 获取网页源码。

    向服务器发送 HTTP 请求。获取到网页源码。

  7. 使用正则表达式解析网页源码。

    • 如果是图片 URL 就放进先前创建好的数组中。
    • 如果是其他 URL 就放进队列中,让其后续循环处理。
  8. 下载图片。

    循环遍历刚才存放图片的数组,重新对图片的 URL 建立连接和获取源码。

    去除服务器返回的 HTTP 头部信息,将正文信息写到一个新创建的文件里,放到之前创建的文件夹。

spider's People

Contributors

gdis5251 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.