自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

那些有趣好玩強(qiáng)大的Python庫(kù)

開(kāi)發(fā) 前端
equests 庫(kù)的作者——kennethreitz,寫(xiě)的 Python 入門(mén)教程。不單單是語(yǔ)法層面的,涵蓋項(xiàng)目結(jié)構(gòu)、代碼風(fēng)格,進(jìn)階、工具等方方面面。

ython 語(yǔ)言向來(lái)以豐富的第三方庫(kù)而聞名,今天來(lái)介紹幾個(gè)非常nice的庫(kù),有趣好玩且強(qiáng)大!

數(shù)據(jù)采集

在當(dāng)今互聯(lián)網(wǎng)時(shí)代,數(shù)據(jù)實(shí)在是太重要了,首先我們就來(lái)介紹幾個(gè)優(yōu)秀的數(shù)據(jù)采集項(xiàng)目

AKShare

AKShare 是基于 Python 的財(cái)經(jīng)數(shù)據(jù)接口庫(kù),目的是實(shí)現(xiàn)對(duì)股票、期貨、期權(quán)、基金、外匯、債券、指數(shù)、加密貨幣等金融產(chǎn)品的基本面數(shù)據(jù)、實(shí)時(shí)和歷史行情數(shù)據(jù)、衍生數(shù)據(jù)從數(shù)據(jù)采集、數(shù)據(jù)清洗到數(shù)據(jù)落地的一套工具,主要用于學(xué)術(shù)研究目的。

import akshare as ak

stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20170301", end_date='20210907', adjust="")
print(stock_zh_a_hist_df)

Output:

      日期          開(kāi)盤(pán)   收盤(pán)    最高  ...  振幅   漲跌幅 漲跌額 換手率
0 2017-03-01 9.49 9.49 9.55 ... 0.84 0.11 0.01 0.21
1 2017-03-02 9.51 9.43 9.54 ... 1.26 -0.63 -0.06 0.24
2 2017-03-03 9.41 9.40 9.43 ... 0.74 -0.32 -0.03 0.20
3 2017-03-06 9.40 9.45 9.46 ... 0.74 0.53 0.05 0.24
4 2017-03-07 9.44 9.45 9.46 ... 0.63 0.00 0.00 0.17
... ... ... ... ... ... ... ... ...
1100 2021-09-01 17.48 17.88 17.92 ... 5.11 0.45 0.08 1.19
1101 2021-09-02 18.00 18.40 18.78 ... 5.48 2.91 0.52 1.25
1102 2021-09-03 18.50 18.04 18.50 ... 4.35 -1.96 -0.36 0.72
1103 2021-09-06 17.93 18.45 18.60 ... 4.55 2.27 0.41 0.78
1104 2021-09-07 18.60 19.24 19.56 ... 6.56 4.28 0.79 0.84
[1105 rows x 11 columns]

https://github.com/akfamily/akshare

TuShare

TuShare 是實(shí)現(xiàn)對(duì)股票/期貨等金融數(shù)據(jù)從數(shù)據(jù)采集、清洗加工到數(shù)據(jù)存儲(chǔ)過(guò)程的工具,滿足金融量化分析師和學(xué)習(xí)數(shù)據(jù)分析的人在數(shù)據(jù)獲取方面的需求,它的特點(diǎn)是數(shù)據(jù)覆蓋范圍廣,接口調(diào)用簡(jiǎn)單,響應(yīng)快速。

不過(guò)該項(xiàng)目有一部分功能是收費(fèi)的,大家選擇使用哦

import tushare as ts

ts.get_hist_data('600848') #一次性獲取全部數(shù)據(jù)

Output:

       open    high   close     low     volume    p_change  ma5 \
date
2012-01-11 6.880 7.380 7.060 6.880 14129.96 2.62 7.060
2012-01-12 7.050 7.100 6.980 6.900 7895.19 -1.13 7.020
2012-01-13 6.950 7.000 6.700 6.690 6611.87 -4.01 6.913
2012-01-16 6.680 6.750 6.510 6.480 2941.63 -2.84 6.813
2012-01-17 6.660 6.880 6.860 6.460 8642.57 5.38 6.822
2012-01-18 7.000 7.300 6.890 6.880 13075.40 0.44 6.788
2012-01-19 6.690 6.950 6.890 6.680 6117.32 0.00 6.770
2012-01-20 6.870 7.080 7.010 6.870 6813.09 1.74 6.832

ma10 ma20 v_ma5 v_ma10 v_ma20 turnover
date
2012-01-11 7.060 7.060 14129.96 14129.96 14129.96 0.48
2012-01-12 7.020 7.020 11012.58 11012.58 11012.58 0.27
2012-01-13 6.913 6.913 9545.67 9545.67 9545.67 0.23
2012-01-16 6.813 6.813 7894.66 7894.66 7894.66 0.10
2012-01-17 6.822 6.822 8044.24 8044.24 8044.24 0.30
2012-01-18 6.833 6.833 7833.33 8882.77 8882.77 0.45
2012-01-19 6.841 6.841 7477.76 8487.71 8487.71 0.21
2012-01-20 6.863 6.863 7518.00 8278.38 8278.38 0.23

https://github.com/waditu/tushare

GoPUP

GoPUP 項(xiàng)目所采集的數(shù)據(jù)皆來(lái)自公開(kāi)的數(shù)據(jù)源,不涉及任何個(gè)人隱私數(shù)據(jù)和非公開(kāi)數(shù)據(jù)。不過(guò)同樣的,部分接口是需要注冊(cè) TOKEN 才能使用的。

import gopup as gp
df = gp.weibo_index(word="疫情", time_type="1hour")
print(df)

Output:

                        疫情
index
2022-12-17 18:15:00 18544
2022-12-17 18:20:00 14927
2022-12-17 18:25:00 13004
2022-12-17 18:30:00 13145
2022-12-17 18:35:00 13485
2022-12-17 18:40:00 14091
2022-12-17 18:45:00 14265
2022-12-17 18:50:00 14115
2022-12-17 18:55:00 15313
2022-12-17 19:00:00 14346
2022-12-17 19:05:00 14457
2022-12-17 19:10:00 13495
2022-12-17 19:15:00 14133

https://github.com/justinzm/gopup

GeneralNewsExtractor

該項(xiàng)目基于《基于文本及符號(hào)密度的網(wǎng)頁(yè)正文提取方法》論文,使用 Python 實(shí)現(xiàn)的正文抽取器,可以用來(lái)提取 HTML 中正文的內(nèi)容、作者、標(biāo)題。

>>> from gne import GeneralNewsExtractor

>>> html = '''經(jīng)過(guò)渲染的網(wǎng)頁(yè) HTML 代碼'''

>>> extractor = GeneralNewsExtractor()
>>> result = extractor.extract(html, noise_node_list=['//div[@class="comment-list"]'])
>>> print(result)

Output:

{"title": "xxxx", "publish_time": "2019-09-10 11:12:13", "author": "yyy", "content": "zzzz", "images": ["/xxx.jpg", "/yyy.png"]}

新聞頁(yè)提取示例

圖片

https://github.com/GeneralNewsExtractor/GeneralNewsExtractor

爬蟲(chóng)

爬蟲(chóng)也是 Python 語(yǔ)言的一大應(yīng)用方向,很多朋友也都是以爬蟲(chóng)來(lái)入門(mén)的,我們來(lái)看看有哪些優(yōu)秀的爬蟲(chóng)項(xiàng)目吧

playwright-python

微軟開(kāi)源的瀏覽器自動(dòng)化工具,可以用 Python 語(yǔ)言操作瀏覽器。支持 Linux、macOS、Windows 系統(tǒng)下的 Chromium、Firefox 和 WebKit 瀏覽器。

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = browser_type.launch()
page = browser.new_page()
page.goto('http://whatsmyuseragent.org/')
page.screenshot(path=f'example-{browser_type.name}.png')
browser.close()

https://github.com/microsoft/playwright-python

awesome-python-login-model

該項(xiàng)目收集了各大網(wǎng)站登陸方式和部分網(wǎng)站的爬蟲(chóng)程序。登陸方式實(shí)現(xiàn)包含 selenium 登錄、通過(guò)抓包直接模擬登錄等。有助于新手研究、編寫(xiě)爬蟲(chóng)。

不過(guò)眾所周知,爬蟲(chóng)是非常吃后期維護(hù)的,該項(xiàng)目已經(jīng)很久沒(méi)有更新了,所以各種登錄接口是否還能正常使用,還存在疑問(wèn),大家選擇使用,或者自行二次開(kāi)發(fā)。

圖片

https://github.com/Kr1s77/awesome-python-login-model

DecryptLogin

相比于上一個(gè),該項(xiàng)目則還在持續(xù)更新,同樣是模擬登錄各大網(wǎng)站,對(duì)于新手還是非常有研究?jī)r(jià)值的。

from DecryptLogin import login

# the instanced Login class object
lg = login.Login()
# use the provided api function to login in the target website (e.g., twitter)
infos_return, session = lg.twitter(username='Your Username', password='Your Password')

https://github.com/CharlesPikachu/DecryptLogin

Scylla

Scylla 是一款高質(zhì)量的免費(fèi)代理 IP 池工具,當(dāng)前僅支持 Python 3.6。

http://localhost:8899/api/v1/stats

Output:

{
"median": 181.2566407083,
"valid_count": 1780,
"total_count": 9528,
"mean": 174.3290085201
}

https://github.com/scylladb/scylladb

ProxyPool

爬蟲(chóng)代理IP池項(xiàng)目,主要功能為定時(shí)采集網(wǎng)上發(fā)布的免費(fèi)代理驗(yàn)證入庫(kù),定時(shí)驗(yàn)證入庫(kù)的代理保證代理的可用性,提供API和CLI兩種使用方式。同時(shí)也可以擴(kuò)展代理源以增加代理池IP的質(zhì)量和數(shù)量。該項(xiàng)目設(shè)計(jì)文檔詳細(xì)、模塊結(jié)構(gòu)簡(jiǎn)明易懂,同時(shí)適合爬蟲(chóng)新手更好的學(xué)習(xí)爬蟲(chóng)技術(shù)。

import requests

def get_proxy():
return requests.get("http://127.0.0.1:5010/get/").json()

def delete_proxy(proxy):
requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))

# your spider code

def getHtml():
# ....
retry_count = 5
proxy = get_proxy().get("proxy")
while retry_count > 0:
try:
html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
# 使用代理訪問(wèn)
return html
except Exception:
retry_count -= 1
# 刪除代理池中代理
delete_proxy(proxy)
return None

https://github.com/Python3WebSpider/ProxyPool

getproxy

getproxy 是一個(gè)抓取發(fā)放代理網(wǎng)站,獲取 http/https 代理的程序,每 15 min 更新數(shù)據(jù)。

(test2.7) ?  ~ getproxy
INFO:getproxy.getproxy:[*] Init
INFO:getproxy.getproxy:[*] Current Ip Address: 1.1.1.1
INFO:getproxy.getproxy:[*] Load input proxies
INFO:getproxy.getproxy:[*] Validate input proxies
INFO:getproxy.getproxy:[*] Load plugins
INFO:getproxy.getproxy:[*] Grab proxies
INFO:getproxy.getproxy:[*] Validate web proxies
INFO:getproxy.getproxy:[*] Check 6666 proxies, Got 666 valid proxies
...

https://github.com/fate0/getproxy

freeproxy

同樣是一個(gè)抓取免費(fèi)代理的項(xiàng)目,該項(xiàng)目支持抓取的代理網(wǎng)站非常多,而且使用簡(jiǎn)單。

from freeproxy import freeproxy

proxy_sources = ['proxylistplus', 'kuaidaili']
fp_client = freeproxy.FreeProxy(proxy_sources=proxy_sources)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
}
response = fp_client.get('https://space.bilibili.com/406756145', headers=headers)
print(response.text)

https://github.com/CharlesPikachu/freeproxy

fake-useragent

偽裝瀏覽器身份,常用于爬蟲(chóng)。這個(gè)項(xiàng)目的代碼很少,可以閱讀一下,看看ua.random是如何返回隨機(jī)的瀏覽器身份的。

from fake_useragent import UserAgent
ua = UserAgent()

ua.ie
# Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
ua.msie
# Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)'
ua['Internet Explorer']
# 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)
ua.opera
# Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11
ua.chrome
# Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'
ua.google
# Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13
ua['google chrome']
# Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
ua.firefox
# Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1
ua.ff
# Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0.1
ua.safari
# Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25

# and the best one, get a random browser user-agent string
ua.random

https://github.com/fake-useragent/fake-useragent

Web 相關(guān)

Python Web 有太多優(yōu)秀且老牌的庫(kù)了,比如 Django,F(xiàn)lask 就不說(shuō)了,大家都知道,我們介紹幾個(gè)小眾但是好用的。

streamlit

streamlit 能夠快速地把數(shù)據(jù)制作成可視化、交互頁(yè)面的 Python 框架。分分鐘讓我們的數(shù)據(jù)變成圖表。

import streamlit as st

x = st.slider('Select a value')
st.write(x, 'squared is', x * x)

Output:

圖片

https://github.com/streamlit/streamlit

wagtail

是一個(gè)強(qiáng)大的開(kāi)源 Django CMS(內(nèi)容管理系統(tǒng))。首先該項(xiàng)目更新、迭代活躍,其次項(xiàng)目首頁(yè)提到的功能都是免費(fèi)的,沒(méi)有付費(fèi)解鎖的騷操作。專注于內(nèi)容管理,不束縛前端實(shí)現(xiàn)。

圖片

https://github.com/wagtail/wagtail

fastapi

基于 Python 3.6+ 的高性能 Web 框架?!叭巳缙涿庇?FastAPI 寫(xiě)接口那叫一個(gè)快、調(diào)試方便,Python 在進(jìn)步而它基于這些進(jìn)步,讓 Web 開(kāi)發(fā)變得更快、更強(qiáng)。

from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}

https://github.com/tiangolo/fastapi

django-blog-tutorial

這是一個(gè) Django 使用教程,該項(xiàng)目一步步帶我們使用 Django 從零開(kāi)發(fā)一個(gè)個(gè)人博客系統(tǒng),在實(shí)踐的同時(shí)掌握 Django 的開(kāi)發(fā)技巧。

https://github.com/jukanntenn/django-blog-tutorial

dash

dash 是一個(gè)專門(mén)為機(jī)器學(xué)習(xí)而來(lái)的 Web 框架,通過(guò)該框架可以快速搭建一個(gè)機(jī)器學(xué)習(xí) APP。

圖片

https://github.com/plotly/dash

PyWebIO

同樣是一個(gè)非常優(yōu)秀的 Python Web 框架,在不需要編寫(xiě)前端代碼的情況下就可以完成整個(gè) Web 頁(yè)面的搭建,實(shí)在是方便。

圖片

https://github.com/pywebio/PyWebIO

Python 教程

practical-python

一個(gè)人氣超高的 Python 學(xué)習(xí)資源項(xiàng)目,是 MarkDown 格式的教程,非常友好。

https://github.com/dabeaz-course/practical-python

learn-python3

一個(gè) Python3 的教程,該教程采用 Jupyter notebooks 形式,便于運(yùn)行和閱讀。并且還包含了練習(xí)題,對(duì)新手友好。

https://github.com/jerry-git/learn-python3

python-guide

Requests 庫(kù)的作者——kennethreitz,寫(xiě)的 Python 入門(mén)教程。不單單是語(yǔ)法層面的,涵蓋項(xiàng)目結(jié)構(gòu)、代碼風(fēng)格,進(jìn)階、工具等方方面面。一起在教程中領(lǐng)略大神的風(fēng)采吧~

https://github.com/realpython/python-guide

其他

pytools

這是一位大神編寫(xiě)的類似工具集的項(xiàng)目,里面包含了眾多有趣的小工具。

圖片

截圖只是冰山一角,全貌需要大家自行探索了

import random
from pytools import pytools

tool_client = pytools.pytools()
all_supports = tool_client.getallsupported()
tool_client.execute(random.choice(list(all_supports.values())))

https://github.com/CharlesPikachu/pytools

amazing-qr

可以生成動(dòng)態(tài)、彩色、各式各樣的二維碼,真是個(gè)有趣的庫(kù)。

#3 -n, -d
amzqr https://github.com -n github_qr.jpg -d .../paths/

https://github.com/x-hw/amazing-qr

sh

sh 是一個(gè)成熟的,用于替代 subprocess 的庫(kù),它允許我們調(diào)用任何程序,看起來(lái)它就是一個(gè)函數(shù)一樣。

$> ./run.sh FunctionalTests.test_unicode_arg

https://github.com/amoffat/sh

tqdm

強(qiáng)大、快速、易擴(kuò)展的 Python 進(jìn)度條庫(kù)。

from tqdm import tqdm
for i in tqdm(range(10000)):
...

https://github.com/tqdm/tqdm

loguru

一個(gè)讓 Python 記錄日志變得簡(jiǎn)單的庫(kù)。

from loguru import logger

logger.debug("That's it, beautiful and simple logging!")

https://github.com/Delgan/loguru

click

Python 的第三方庫(kù),用于快速創(chuàng)建命令行。支持裝飾器方式調(diào)用、多種參數(shù)類型、自動(dòng)生成幫助信息等。

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 _ in range(count):
click.echo(f"Hello, {name}!")

if __name__ == '__main__':
hello()

Output:

$ python hello.py --count=3
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!

KeymouseGo

Python 實(shí)現(xiàn)的精簡(jiǎn)綠色版按鍵精靈,記錄用戶的鼠標(biāo)、鍵盤(pán)操作,自動(dòng)執(zhí)行之前記錄的操作,可設(shè)定執(zhí)行的次數(shù)。在進(jìn)行某些簡(jiǎn)單、單調(diào)重復(fù)的操作時(shí),使用該軟件可以十分省事兒。只需要錄制一遍,剩下的交給 KeymouseGo 來(lái)做就可以了。

圖片

https://github.com/taojy123/KeymouseGo

責(zé)任編輯:武曉燕 來(lái)源: 蘿卜大雜燴
相關(guān)推薦

2017-08-08 16:04:30

Python圖片處理文章提取器

2010-04-09 11:07:40

Oracle 有趣排序

2019-01-22 05:33:59

2022-03-29 10:56:46

Pythonblinker信號(hào)庫(kù)

2011-06-13 10:30:07

Linus Torva

2020-07-13 07:27:16

Python庫(kù)開(kāi)發(fā)

2021-07-21 08:59:10

requestsPython協(xié)程

2011-10-10 14:05:08

jQuery插件

2022-03-28 08:36:15

tenacityPython庫(kù)

2022-05-11 12:12:32

ScapyPython網(wǎng)絡(luò)包

2013-01-14 10:23:32

2022-03-31 11:56:34

Android 12智能手機(jī)功能

2022-06-30 09:00:23

Vue.js版本名稱

2024-06-06 09:23:11

2010-03-26 13:39:28

Python標(biāo)準(zhǔn)庫(kù)

2021-07-13 10:59:49

Python庫(kù)可視化

2024-05-15 17:10:56

2020-03-21 20:08:23

物聯(lián)網(wǎng)人工智能智能恒溫器

2018-09-08 17:45:26

2020-07-29 10:00:38

PythonEllipsis索引
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)