那些有趣又有用的 Python 庫
圖片處理
pip install pillow
from PIL import Image
import numpy as np
a = np.array(Image.open("test.jpg"))
b = [255,255,255] - a
im = Image.fromarray(b.astype("uint8"))
im.save("new.jpg")
youtube-dl下載國外視頻
pip install youtube-dl #直接安裝youtube-dl
pip install -U youtube-dl #安裝youtube-dl並更新
查看對象的全部屬性和方法
pip install pdir2
>>> import pdir,requests
>>> pdir(requests)
module attribute:
__cached__, __file__, __loader__, __name__, __package__, __path__, __spec__
other:
__author__, __build__, __builtins__, __copyright__, __license__, __title__,
__version__, _internal_utils, adapters, api, auth, certs, codes, compat, cookies
, exceptions, hooks, logging, models, packages, pyopenssl, sessions, status_code
s, structures, utils, warnings
special attribute:
__doc__
class:
NullHandler: This handler does nothing. It"s intended to be used to avoid th
e
PreparedRequest: The fully mutable :class:`PreparedRequest
` object,
Request: A user-created :class:`Request ` object.
Response: The :class:`Response ` object, which contains a
Session: A Requests session.
exception:
ConnectTimeout: The request timed out while trying to connect to the remote
server.
ConnectionError: A Connection error occurred.
DependencyWarning: Warned when an attempt is made to import a module with mi
ssing optional
FileModeWarning: A file was opened in text mode, but Requests determined its
binary length.
HTTPError: An HTTP error occurred.
ReadTimeout: The server did not send any data in the allotted amount of time
.
RequestException: There was an ambiguous exception that occurred while handl
ing your
Timeout: The request timed out.
TooManyRedirects: Too many redirects.
URLRequired: A valid URL is required to make a request.
function:
delete: Sends a DELETE request.
get: Sends a GET request.
head: Sends a HEAD request.
options: Sends a OPTIONS request.
patch: Sends a PATCH request.
post: Sends a POST request.
put: Sends a PUT request.
request: Constructs and sends a :class:`Request `.
session: Returns a :class:`Session` for context-management.
想要系統學習python和免費學習資料的 可以加裙 四七四五三四九五一
Python 玩轉網易雲音樂
pip install ncmbot
import ncmbot
#登錄
bot = ncmbot.login(phone="xxx", password="yyy")
bot.content # bot.json()
#獲取用戶歌單
下載視頻字幕
pip install getsub
Python 財經數據介麵包
pip install tushare
import tushare as ts
#一次性獲取最近一個日交易日所有股票的交易數據
ts.get_today_all()
代碼,名稱,漲跌幅,現價,開盤價,最高價,最低價,最日收盤價,成交量,換手率
code name changepercent trade open high low settlement
0 002738 中礦資源 10.023 19.32 19.32 19.32 19.32 17.56
1 300410 正業科技 10.022 25.03 25.03 25.03 25.03 22.75
2 002736 國信證券 10.013 16.37 16.37 16.37 16.37 14.88
3 300412 迦南科技 10.010 31.54 31.54 31.54 31.54 28.67
4 300411 金盾股份 10.007 29.68 29.68 29.68 29.68 26.98
5 603636 南威軟體 10.006 38.15 38.15 38.15 38.15 34.68
6 002664 信質電機 10.004 30.68 29.00 30.68 28.30 27.89
7 300367 東方網力 10.004 86.76 78.00 86.76 77.87 78.87
8 601299 中國北車 10.000 11.44 11.44 11.44 11.29 10.40
9 601880 大連港 10.000 5.72 5.34 5.72 5.22 5.20
10 000856 冀東裝備 10.000 8.91 8.18 8.91 8.18 8.10
開源漏洞靶場
# 安裝pip
curl -s https://bootstrap.pypa.io/get-pip.py | python3
# 安裝docker
apt-get update && apt-get install docker.io
# 啟動docker服務
service docker start
# 安裝compose
pip install docker-compose
# 拉取項目
cd vulhub
# 進入某一個漏洞/環境的目錄
cd nginx_php5_mysql
# 自動化編譯環境
docker-compose build
# 啟動整個環境
docker-compose up -d
#測試完成後,刪除整個環境
docker-compose down
北京實時公交
pip install -r requirements.txt 安裝依賴
python manage.py build_cache 獲取離線數據,建立本地緩存
#項目自帶了一個終端中的查詢工具作為例子,運行: python manage.py cli
>>> from beijing_bus import BeijingBus
>>> lines = BeijingBus.get_all_lines()
[
,
, ...]
>>> lines = BeijingBus.search_lines("847")
[
,
]
>>> line = lines[0]
>>> print line.id, line.name
541 847(馬甸橋西-雷庄村)
>>> line.stations
[, , , ...]
>>> station = line.stations[0]
>>> print station.name, station.lat, station.lon
馬甸橋西 39.967721 116.372921
>>> line.get_realtime_data(1) # 參數為站點的序號,從1開始
[
{
"id": 公交車id,
"lat": 公交車的位置,
"lon": 公交車位置,
"next_station_name": 下一站的名字,
"next_station_num": 下一站的序號,
"next_station_distance": 離下一站的距離,
"next_station_arriving_time": 預計到達下一站的時間,
"station_distance": 離本站的距離,
"station_arriving_time": 預計到達本站的時間,
},
...
]
文章提取器
git clone https://github.com/grangier/python-goose.git
cd python-goose
pip install -r requirements.txt
python setup.py install
>>> from goose import Goose
>>> from goose.text import StopWordsChinese
>>> url = "http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml"
>>> g = Goose({"stopwords_class": StopWordsChinese})
>>> article = g.extract(url=url)
>>> print article.cleaned_text[:150]
香港行政長官梁振英在各方壓力下就其大宅的違章建築(僭建)問題到立法會接受質詢,並向香港民眾道歉。
梁振英在星期二(12月10日)的答問大會開始之際在其演說中道歉,但強調他在違章建築問題上沒有隱瞞的意圖和動機。
一些親北京陣營議員歡迎梁振英道歉,且認為應能獲得香港民眾接受,但這些議員也質問梁振英有
Python 藝術二維碼生成器
pip install MyQR
myqr https://github.com
myqr https://github.com -v 10 -l Q
想要系統學習python和免費學習資料的 可以加裙 四七四五三四九五一
※C語言編程時常犯的18種錯誤
※html css零基礎入門教程 一
※看我如何基於Python和Facepp打造智能監控系統
TAG:IT技術java交流 |
※你用 Python 做過什麼有趣的數據挖掘項目?
※啟動Python的方法有哪些?
※Python帶我飛:50個有趣而又鮮為人知的Python特性
※到底有沒有必要學習Python
※利用Python對QQ群進行爬蟲,只有你想不到的,沒有Python做不到的
※Python之父:為什麼操作符很有用?
※這個使用 Python 編寫的 PDF 神器你值得擁有!
※有趣的一行 Python 代碼
※想做Python開發,這14種常用Python模塊,你必須知道!
※十大Python機器學習常用庫 python開發,你用過幾個?
※WTF Python:有趣且鮮為人知的Python特性
※為啥子要用ipython
※Python到底有什麼用,應該怎麼學?
※Python讀寫Excel表格,就是這麼簡單粗暴又好用
※為什麼 Python 這麼慢?
※10個Python常見面試題,這些弄不明白不要說學過Python!
※這還是我認識的Python嗎!
※一些很棒的Python應用程序
※利用你所知道的Python技巧寫出更加Pythonic的代碼
※你都用Python做過哪些騷操作?