-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcve_crawler.py
More file actions
35 lines (23 loc) · 795 Bytes
/
Copy pathcve_crawler.py
File metadata and controls
35 lines (23 loc) · 795 Bytes
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
import requests
import json
def read_cve(keyword):
try:
r = requests.get(f'https://services.nvd.nist.gov/rest/json/cves/2.0?keywordSearch={keyword}')
return r.json()
except Exception as e:
print(f"read cve error occurred:{keyword} {e}")
return None
def read_keyword(filepath):
with open(filepath, 'r') as file:
keywords = [line.strip() for line in file if line.strip()]
return keywords
def write_json(data,filepath):
with open(filepath, 'w') as file:
json.dump(data,file,indent=4)
def process_data(filepath):
keywords = read_keyword(filepath)
for keyword in keywords:
cves = read_cve(keyword)
write_json(cves, f"{keyword}.json")
print(f"Processed {keyword}")
process_data("repos.txt")