自从收了这些Python库 头发都不脱了!


01

图片处理

1. pip install pillow

2. from PIL import Image

3. import numpy as np

4.

5. a = np.array(Image.open('test.jpg'))

6. b = [255,255,255] - a

7. im = Image.fromarray(b.astype('uint8'))

8. im.save('new.jpg')

02

youtube-dl下载国外视频

1. #https://github.com/rg3/youtube-dl/

2. pip install youtube-dl #直接安装youtube-dl

3. pip install -U youtube-dl #安装youtube-dl并更新

4. youtube-dl "http://www.youtube.com/watch?v=-wNyEUrxzFU"

03

查看对象的全部属性和方法

1. pip install pdir2

2. >>> import pdir,requests

3. >>> pdir(requests)

4. module attribute:

5. __cached__, __file__, __loader__, __name__, __package__, __path__, __spec__

6. other:

7. __author__, __build__, __builtins__, __copyright__, __license__, __title__,

8. __version__, _internal_utils, adapters, api, auth, certs, codes, compat, cookies

9. , exceptions, hooks, logging, models, packages, pyopenssl, sessions, status_code

10. s, structures, utils, warnings

11. special attribute:

12. __doc__

13. class:

14. NullHandler: This handler does nothing. It's intended to be used to avoid th

15. e

16. PreparedRequest: The fully mutable :class:`PreparedRequest <PreparedRequest>

17. ` object,

18. Request: A user-created :class:`Request <Request>` object.

19. Response: The :class:`Response <Response>` object, which contains a

20. Session: A Requests session.

21. exception:

22. ConnectTimeout: The request timed out while trying to connect to the remote

23. server.

24. ConnectionError: A Connection error occurred.

25. DependencyWarning: Warned when an attempt is made to import a module with mi

26. ssing optional

27. FileModeWarning: A file was opened in text mode, but Requests determined its

28. binary length.

29. HTTPError: An HTTP error occurred.

30. ReadTimeout: The server did not send any data in the allotted amount of time

31. .

32. RequestException: There was an ambiguous exception that occurred while handl

33. ing your

34. Timeout: The request timed out.

35. TooManyRedirects: Too many redirects.

36. URLRequired: A valid URL is required to make a request.

37. function:

38. delete: Sends a DELETE request.

39. get: Sends a GET request.

40. head: Sends a HEAD request.

41. options: Sends a OPTIONS request.

42. patch: Sends a PATCH request.

43. post: Sends a POST request.

44. put: Sends a PUT request.

45. request: Constructs and sends a :class:`Request <Request>`.

46. session: Returns a :class:`Session` for context-management.

04

Python 玩转网易云音乐

1. #https://github.com/xiyouMc/ncmbot

2. pip install ncmbot

3. import ncmbot

4. #登录

5. bot = ncmbot.login(phone='xxx', password='yyy')

6. bot.content # bot.json()

7. #获取用户歌单

8. ncmbot.user_play_list(uid='36554272')

05

下载视频字幕

1. #https://github.com/gyh1621/GetSubtitles

2. pip install getsub

06

Python 财经数据接口包

1. # https://github.com/waditu/tushare

2. pip install tushare

3. import tushare as ts

4. #一次性获取最近一个日交易日所有股票的交易数据

5. ts.get_today_all()

6.

7. 代码,名称,涨跌幅,现价,开盘价,最高价,最低价,最日收盘价,成交量,换手率

8. code name changepercent trade open high low settlement \

9. 0 002738 中矿资源 10.023 19.32 19.32 19.32 19.32 17.56

10. 1 300410 正业科技 10.022 25.03 25.03 25.03 25.03 22.75

11. 2 002736 国信证券 10.013 16.37 16.37 16.37 16.37 14.88

12. 3 300412 迦南科技 10.010 31.54 31.54 31.54 31.54 28.67

13. 4 300411 金盾股份 10.007 29.68 29.68 29.68 29.68 26.98

14. 5 603636 南威软件 10.006 38.15 38.15 38.15 38.15 34.68

15. 6 002664 信质电机 10.004 30.68 29.00 30.68 28.30 27.89

16. 7 300367 东方网力 10.004 86.76 78.00 86.76 77.87 78.87

17. 8 601299 中国北车 10.000 11.44 11.44 11.44 11.29 10.40

18. 9 601880 大连港 10.000 5.72 5.34 5.72 5.22 5.20

19. 10 000856 冀东装备 10.000 8.91 8.18 8.91 8.18 8.10

07

开源漏洞靶场

1. # https://github.com/phith0n/vulhub 安装pip

2. curl -s https://bootstrap.pypa.io/get-pip.py | python3

3.

4. # 安装docker

5. apt-get update && apt-get install docker.io

6.

7. # 启动docker服务

8. service docker start

9.

10. # 安装compose

11. pip install docker-compose

12. # 拉取项目

13. git clone git@github.com:phith0n/vulhub.git

14. cd vulhub

15.

16. # 进入某一个漏洞/环境的目录

17. cd nginx_php5_mysql

18.

19. # 自动化编译环境

20. docker-compose build

21.

22. # 启动整个环境

23. docker-compose up -d

24. #测试完成后,删除整个环境

25. docker-compose down

08

北京实时公交

1. #https://github.com/wong2/beijing_bus

2. pip install -r requirements.txt 安装依赖

3. python manage.py build_cache 获取离线数据,建立本地缓存

4. #项目自带了一个终端中的查询工具作为例子,运行: python manage.py cli

5. >>> from beijing_bus import BeijingBus

6. >>> lines = BeijingBus.get_all_lines()

7. >>> lines

8. [<Line: 运通122(农业展览馆-华纺易城公交场站)>, <Line: 运通101(广顺南大街北口-蓝龙家园)>, ...]

9. >>> lines = BeijingBus.search_lines('847')

10. >>> lines

11. [<Line: 847(马甸桥西-雷庄村)>, <Line: 847(雷庄村-马甸桥西)>]

12. >>> line = lines[0]

13. >>> print line.id, line.name

14. 541 847(马甸桥西-雷庄村)

15. >>> line.stations

16. [<Station 马甸桥西>, <Station 马甸桥东>, <Station 安华桥西>, ...]

17. >>> station = line.stations[0]

18. >>> print station.name, station.lat, station.lon

19. 马甸桥西 39.967721 116.372921

20. >>> line.get_realtime_data(1) # 参数为站点的序号,从1开始

21. [

22. {

23. 'id': 公交车id,

24. 'lat': 公交车的位置,

25. 'lon': 公交车位置,

26. 'next_station_name': 下一站的名字,

27. 'next_station_num': 下一站的序号,

28. 'next_station_distance': 离下一站的距离,

29. 'next_station_arriving_time': 预计到达下一站的时间,

30. 'station_distance': 离本站的距离,

31. 'station_arriving_time': 预计到达本站的时间,

32. },

33. ...

34. ]

09

文章提取器

1. #https://github.com/grangier/python-goose

2. git clone https://github.com/grangier/python-goose.git

3. cd python-goose

4. pip install -r requirements.txt

5. python setup.py install

6.

7. >>> from goose import Goose

8. >>> from goose.text import StopWordsChinese

9. >>> url = 'http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml'

10. >>> g = Goose({'stopwords_class': StopWordsChinese})

11. >>> article = g.extract(url=url)

12. >>> print article.cleaned_text[:150]

13. 香港行政长官梁振英在各方压力下就其大宅的违章建筑(僭建)问题到立法会接受质询,并向香港民众道歉。

14.

15. 梁振英在星期二(12月10日)的答问大会开始之际在其演说中道歉,但强调他在违章建筑问题上没有隐瞒的意图和动机。

16.

17. 一些亲北京阵营议员欢迎梁振英道歉,且认为应能获得香港民众接受,但这些议员也质问梁振英有

10

Python 艺术二维码生成器

1. #https://github.com/sylnsfar/qrcode

2. pip install MyQR

3. myqr https://github.com

4. myqr https://github.com -v 10 -l Q

11

伪装浏览器身份

1. #https://github.com/hellysmile/fake-useragent

2. pip install fake-useragent

3. from fake_useragent import UserAgent

4. ua = UserAgent()

5.

6. ua.ie

7. # Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);

8. ua.msie

9. # Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)'

10. ua['Internet Explorer']

11. # Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)

12. ua.opera

13. # Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11

14. ua.chrome

15. # Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'

12

美化 curl

1. #https://github.com/reorx/httpstat

2. pip install httpstat

3. httpstat httpbin.org/get

13

python shell

1. #https://github.com/amoffat/sh

2. pip install sh

3. from sh import ifconfig

4. print ifconfig("eth0")

14

处理中文文本内容

1. #https://github.com/isnowfy/snownlp

2. pip install snownlp

3. from snownlp import SnowNLP

4.

5. s = SnowNLP(u'这个东西真心很赞')

6.

7. s.words # [u'这个', u'东西', u'真心',

8. # u'很', u'赞']

9.

10. s.tags # [(u'这个', u'r'), (u'东西', u'n'),

11. # (u'真心', u'd'), (u'很', u'd'),

12. # (u'赞', u'Vg')]

13.

14. s.sentiments # 0.9769663402895832 positive的概率

15.

16. s.pinyin # [u'zhe', u'ge', u'dong', u'xi',

17. # u'zhen', u'xin', u'hen', u'zan']

18.

19. s = SnowNLP(u'「繁體字」「繁體中文」的叫法在臺灣亦很常見。')

20.

21. s.han # u'「繁体字」「繁体中文」的叫法

22. # 在台湾亦很常见。'

15

抓取发放代理

1. #https://github.com/fate0/proxylist

2. pip install -U getproxy

3. ➜ ~ getproxy --help

4. Usage: getproxy [OPTIONS]

5.

6. Options:

7. --in-proxy TEXT Input proxy file

8. --out-proxy TEXT Output proxy file

9. --help Show this message and exit.

§ --in-proxy 可选参数,待验证的 proxies 列表文件

§ --out-proxy 可选参数,输出已验证的 proxies 列表文件,如果为空,则直接输出到终端

--in-proxy 文件格式和 --out-proxy 文件格式一致

16

zhihu api

1. pip install git+git://github.com/lzjun567/zhihu-api --upgrade

2. from zhihu import Zhihu

3. zhihu = Zhihu()

4. zhihu.user(user_slug="xiaoxiaodouzi")

5.

6. {'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg',

7. 'badge': [],

8. 'name': '我是小号',

9. 'headline': '程序员',

10. 'gender': -1,

11. 'user_type': 'people',

12. 'is_advertiser': False,

13. 'avatar_url': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg',

14. 'url': 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'type': 'people',

15. 'url_token': 'xiaoxiaodouzi',

16. 'id': '1da75b85900e00adb072e91c56fd9149',

17. 'is_org': False}

17

Python 密码泄露查询模块

1. #https://github.com/lauixData/leakPasswd

2. pip install leakPasswd

3. import leakPasswd

4. leakPasswd.findBreach('taobao')


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值