forked from MR5356/System-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_api.py
More file actions
48 lines (42 loc) · 1.45 KB
/
source_api.py
File metadata and controls
48 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 此文件为自动获取github源码信息的Demo代码,未在项目中使用
# Author:Rui Ma
import requests
from bs4 import BeautifulSoup
def get_info():
url = "https://github.com/MR5356"
for i in range(4):
try:
req = requests.get(url, timeout=30).text
break
except Exception as e:
print(f"Github api: {e}")
if i == 3:
return False
soup = BeautifulSoup(req, 'html.parser')
result = {
'url': [],
'title': [],
'info': [],
'language': [],
}
img_src = soup.findAll("a", {'class': 'text-bold flex-auto min-width-0'})
for img in img_src:
img = img.get('href') # 抓取src
result['url'].append(f"https://github.com/{img}")
img_src = soup.findAll("span", {'class': 'repo'})
for img in img_src:
img = img.text.strip() # 抓取src
result['title'].append(img)
img_src = soup.findAll("p", {'class': 'pinned-item-desc text-gray text-small d-block mt-2 mb-3'})
for img in img_src:
img = img.text.strip() # 抓取src
result['info'].append(img)
img_src = soup.findAll("span", {'itemprop': 'programmingLanguage'})
for img in img_src:
img = img.text.strip() # 抓取src
result['language'].append(img)
result['language'] = result['language'][:len(result['title'])]
return result
if __name__ == '__main__':
result = get_info()
print(result)