Skip to content

Instantly share code, notes, and snippets.

View zxyle's full-sized avatar

Xiang Zheng zxyle

View GitHub Profile
@zxyle
zxyle / bar.py
Last active August 26, 2020 09:33
implement progress bar with Python
def show_progress(has, total):
rate = float(has) / float(total)
rate_num = int(rate * 100)
print('\r%s%% %s' % (rate_num, '#' * int(rate_num / 2)), end='')
for i in range(1, 101):
show_progress(i, 100)
import time
time.sleep(0.5)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Zheng <me@zxyle.cn>
# Desc
from aiohttp import web, ClientSession
async def fetch(session, url):
async with session.get(url) as response:
@zxyle
zxyle / async_crawl_phone_area.py
Created December 23, 2018 04:04
异步采集手机号归属地等信息
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Zheng <me@zxyle.cn>
# 采集网站名称: 异步手机号归属地采集
# 主页url: http://m.ip138.com/mobile.asp/
# 使用步骤:
# Step0: python 3.5+
# Step1: 安装依赖 pip install aiohttp==3.5.0 parsel==1.5.1 motor==2.0.0
# Step2: 创建唯一索引 db.phone.ensureIndex({"phone":1},{"unique":true})
@zxyle
zxyle / query_tingpai.py
Last active December 17, 2018 13:00
query_tingpai.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Zheng <me@zxyle.cn>
# Date: 12/15/18
# Desc: 查询股票是否停牌
# install: pip install tornado==5.1.1
import json
import tornado.ioloop
import tornado.web
@zxyle
zxyle / yunhai.py
Last active June 23, 2018 06:21
云海服务商自动发货
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Zheng <me@zxyle.cn>
# Desc: 云海-自动发货
import time
import base64
from hashlib import md5
import requests
@zxyle
zxyle / crawl_phone_area.py
Created March 9, 2018 09:55
姚沿的手机号归属地抓爬程序
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Zheng <zhengxiang@upg.cn>
# 采集网站名称: 姚沿-手机号归属地抓爬
# 主页url: http://www.ip138.com/sj/
# 采集策略:
from urllib.parse import quote_plus
import pymongo
import requests