All Projects → twtrubiks → crawler_click_tutorial

twtrubiks / crawler_click_tutorial

Licence: MIT license
click tutorial ( crawler ) use python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to crawler click tutorial

Tedivms Flask
Flask starter app with celery, bootstrap, and docker environment
Stars: ✭ 142 (+846.67%)
Mutual labels:  click
ClickableWebView
Simple WebView to Detect click on an image
Stars: ✭ 42 (+180%)
Mutual labels:  click
spot price machine learning
Machine Learning for Spot Prices
Stars: ✭ 25 (+66.67%)
Mutual labels:  click
Toucheffects
Android View点击特效TouchEffects,几行代码为所有控件添加点击效果
Stars: ✭ 167 (+1013.33%)
Mutual labels:  click
XKCD
A minimal command line tool for your daily dose of xkcd comics written in python. Feel free to contribute!
Stars: ✭ 67 (+346.67%)
Mutual labels:  click
Nephos
Project Nephos [GSoC '18]: Automated recording, processing, and uploading of TV streams for Universities.
Stars: ✭ 20 (+33.33%)
Mutual labels:  click
Click
Python composable command line interface toolkit
Stars: ✭ 11,741 (+78173.33%)
Mutual labels:  click
notion scheduler
Allows the creation of recurring tasks in Notion.
Stars: ✭ 17 (+13.33%)
Mutual labels:  command-line-tool
DebounceMonitoring
📑 Add debounce logic for any method in a single line.
Stars: ✭ 44 (+193.33%)
Mutual labels:  click
pyGinit
A simple github automation cli
Stars: ✭ 15 (+0%)
Mutual labels:  click
unity-button-sounds-editor
Editor extension for Unity game engine. It helps to assign AudioClip to buttons and to play sounds by button clicks.
Stars: ✭ 65 (+333.33%)
Mutual labels:  click
MobOff
A CLI to download, convert and send youtube videos to several devices using Pushbullet.
Stars: ✭ 47 (+213.33%)
Mutual labels:  click
jquery-clickout
Handle clickout events with jQuery
Stars: ✭ 23 (+53.33%)
Mutual labels:  click
Python Cfonts
Sexy fonts for the console
Stars: ✭ 143 (+853.33%)
Mutual labels:  click
ansible-taskrunner
Ansible Taskrunner - ansible-playbook wrapper with YAML-abstracted python click cli options!
Stars: ✭ 14 (-6.67%)
Mutual labels:  click
Sphinx Click
A Sphinx plugin to automatically document click-based applications
Stars: ✭ 134 (+793.33%)
Mutual labels:  click
Android-Touch-Helper
开屏跳过-安卓系统的开屏广告自动跳过助手
Stars: ✭ 488 (+3153.33%)
Mutual labels:  click
note-keeper
📓 A tiny bash tool for taking and organizing notes.
Stars: ✭ 58 (+286.67%)
Mutual labels:  command-line-tool
wc18-cli
An easy command line interface for the 2018 World Cup
Stars: ✭ 15 (+0%)
Mutual labels:  click
esque
esque - an operational kafka tool.
Stars: ✭ 22 (+46.67%)
Mutual labels:  click

crawler_click_tutorial

今天教大家用 python 建立屬於自己的 command line tool 😏

由於最近剛好看到 click 這個東西,所以決定要拿之前的小程式來把玩一下 😄

本範例使用之前所寫的簡單爬蟲 eynyCrawlerMega

特色

  • 抓取 eyny 電影區 Mega and Google 文章連結

輸出格式

  • 文字檔 ( 爬蟲結束後會自動開啟文字檔 )

click 教學

安裝 click

pip install click

官方範例 demo

hello.py 程式碼如下

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo('Hello %s!' % name)

if __name__ == '__main__':
    hello()

為什麼要用 click.echo() 而不是 print()呢 ?

因為這樣可以解決一些編碼上的問題 ( 詳細請看 click 的 source code )。

然後我們可以這樣使用

python hello.py --count=3

python hello.py --help

建立 command line tool

接下來介紹建立屬於自己的 command line tool,

可以參考我的 setup.py ,程式碼如下

from setuptools import setup

setup(
    name='crawler_click_tutorial',
    version='0.1',
    py_modules=['crawler_click_tutorial'],
    install_requires=[
        'Click',
        'requests',
        'beautifulsoup4',
    ],
    entry_points='''
        [console_scripts]
        movie=crawler_click_tutorial:cli
    ''',
)

最後只需要在 cmd ( 命令提示字元 ) 執行

pip install --editable .

注意,最後有個 .

以後,只要在 cmd ( 命令提示字元 ) 輸入 movie 即可 !!

執行畫面

首先,讓我們先來看看有什麼指令可以使用

movie --help

movie

超酷 😆 ,還有進度條 😮

最後會自動幫你打開文件

movie --page=5 --output=output_file.txt

簡單防呆機制

movie --page=11

結論

click 真的超讚 👍 , 可以利用它打造出屬於自己的 command line tool ,

不管是娛樂還是加速自己的工作流程都非常方便。

Environment

Python 3.5.3

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡😆

alt tag

贊助者付款

License

MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].