Pythonを使用してGitHubでユーザーのスター付きリポジトリのトップ10を取得しますか?
Gitは最も人気のあるバージョン管理システムであり、何百万もの開発者がプロジェクトまたはファイル(コード)を管理します。ここでは、1か月以内に最もスターの多いリポジトリのトップ10を取得しようとします。
主にGitHubリポジトリをスクレイピングしているため、主に、
を使用します。リポジトリをフェッチするためのRequests&BeautifulSoupライブラリ。
結果をファイルに保存して表示します。位置(星)に基づいた結果と名前とリポジトリが表示されます。
以下はそれを実装するためのコードです:
import requests
from bs4 import BeautifulSoup
r = requests.get('https://github.com/trending/lua?since=monthly')
bs = BeautifulSoup(r.text, 'lxml')
lista_repo = bs.find_all('ol', class_='repo-list')
f1 = open('starred-repos.txt', 'w')
for lr in lista_repo:
aux = lr.find_all('div', class_='d-inline-block col-9 mb-1')
for ld in aux:
rank = ld.find_all('a')
f1.writelines(str(rank))
f1.writelines('\n')
f1.close()
f1 = open('starred-repos.txt', 'r')
texto = []
for x in f1:
if x[0] == '[' and x[1] == '<' and x[2] == 'a':
na = x.split('"')
texto.append(na[1])
f1.close()
f1 = open('starred-repos.txt', 'w')
f1.writelines('{}\t {}\t\t {}\t\n\n'.format('Position ', 'Name ', 'Repositories '))
for i in range(10):
tex= texto[i].split('/')
name = tex[1]
repos = tex[2]
f1.writelines('{}- \t {}\t\t {}'.format(i + 1, name, repos))
f1.writelines('\n')
f1.close()
f1 = open('starred-repos.txt', 'r')
print(f1.read())
f1.close() 出力
Position Name Repositories 1- skywind3000 z.lua 2- Kong kong 3- Gawen WireHub 4- PapyElGringo material-awesome 5- koreader koreader 6- stijnwop guidanceSteering 7- Courseplay courseplay 8- Tencent LuaPanda 9- ntop ntopng 10- awesomeWM awesome
-
PythonのニュースAPIを使用してトップニュースを取得する
News APIは、任意のWebサイトからニュース記事を検索および取得するための非常に有名なAPIです。このAPIを使用すると、誰でも任意のWebサイトからニュースの上位10行を取得できます。 ただし、このAPIを使用するには、APIキーが1つ必要です。 サンプルコード import requests def Topnews(): # BBC news api my_api_key=Api_number” my_url = = https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=my
-
PythonでのCX_Freezeの使用
時々私たちは非常にエキサイティングな何か違うものを作りたいと感じます、そして人間の性質によれば、私たちはいつもそれを共有するのが大好きです。 Pythonもそれらの願いを満たします。 Pythonを使用して、Pythonプログラムを友人と共有したい場合は、それを行うことができます。必要なのは、マシンのプログラムで使用されるすべてのモジュールに同じバージョンのPythonをインストールすることだけです。 まず、 pip install CX_Frezzeを使用してCX_Freezeモジュールをインストールする必要があります コマンドプロンプトのコマンド。 最初のステップは、この割り当て、