Giter Club home page Giter Club logo

zhihucrawler's Introduction

知乎爬虫


需求

  • php >= 7.0
  • swoole 扩展

思路

首先是通过一个主文件传入操作类型,然后从配置文件里拿配置信息。

先拉取用户名,然后通过这个信息拉取用户详细信息。

用户名获取

这是第一个表的内容

先在数据库写三五个种子用户名,然后通过数据库拿到这几个种子用户名,放入redis的链表结构中,

然后对redis的数据一个一个进行循环,每个用户名被拼接成url,随后curl就可以运行起来了。

获取到的页面信息传给分析器进行正则判断处理,随后发送回去。然后控制器把他们存入数据库。

当redis里的数据用完了就再从数据库拿数据。这时候数据库中就有上一轮存入的数据了。

如此循环,直到达到配置文件中要求。

问题

性能问题

性能问题大大的。只是服务器不太好。不敢上多线程了。

编码问题

我对于算法不算很懂,不过好歹知道一些性能问题,能在内存里运行的运算就放内存里了。

之前学了一些设计模式,用起来简直不要太爽!

解决方案

跑在了阿里云的学生机上,好棒

Todo

  • 解耦
  • 日志
  • 更好的错误处理

Usage

  1. 你首先需要拉取代码:
https://github.com/AnnatarHe/zhihuCrawler.git
  1. 运行Database里面的数据库创建的一些东西

  2. 运行index.php

php index.php&
  1. 不出意外的话。。。速度较慢:flushed:

配置

在index.php里有一个常量定义:

define(DEBUG, true);

真正跑数据的时候关掉,就好了

app\Config\里面有一些配置项,需要可以用

zhihucrawler's People

Watchers

James Cloos 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.