GithubHelp home page GithubHelp logo

patan's Introduction

Overview

Patan is a lightweight web crawling framework, used to crawl website pages and extract data from the pages. It can be first helpful tool for data analysis or data mining. The core idea of Patan is inspired by Scrapy

Requirements

  • Python 3.7+

Contributing

  • linter: flake8
  • formatter: yapf

Features

  • Lightweight: pretty easy to learn and get started
  • Fast: powered by asyncio and multiprocessing(TBD)
  • Extensible: both spider and downloader is designed to be opened for custom middlewares

Installation

pip install patan

Get Started

create a new project

patan newproject projectname

generate a spider

cd projectname
patan newspider spidername

define where will your spider start

start_urls = ['http://xxxx.html']

or you can override the start_requests method

def start_requests(self):
        url_tpl = 'http://xxxx?page={}'
        for i in range(1, 200):
            url = url_tpl.format(i)
            yield Request(url=url, callback=self.parse, encoding=self.encoding)

create the item class

@dataclass
class StockItem:
    field1: str
    field2: str
    # fieldn: type

finish the item pipeline

class EastmoneyPipeline:

    def process_item(self, item, spider):
        # save item to database or files
        logger.info(item)

configure the item pipeline

{
    "pipelines": {
        "eastmoney.pipelines.EastmoneyPipeline": 10
    }
}

configure the middlewares if you need it

{
    "spider":{
        "middlewares": {
            "eastmoney.middlewares.EastmoneySpiderMiddleware": 200
        },
    },
    "downloader":{
        "middlewares": {
            "eastmoney.middlewares.EastmoneyDownloaderMiddleware": 200
        }
    }
}

finally, you're able to run the project now.

patan start [projectname|path-to-project]

TODO

  • Settings File
  • Middlewares
  • Exception Handling
  • Throttle Control
  • Item Pipelines
  • Scaffolding CLI
  • Multiprocessing
  • Pause and Resume
  • Statistics Data Collecting
  • Web UI
  • More Protocols Support

Thanks

patan's People

Contributors

20perline avatar

Watchers

 avatar

Forkers

zuoxiatian

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.