Created
February 15, 2020 19:11
-
-
Save rkreddyp/7d642cb7f2b669af99bde8f74cfd9bb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def take_cve_parse_nvd_give_cvssv3(cve): | |
time.sleep(0.5) | |
base_url = 'https://nvd.nist.gov/vuln/detail/' | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', 'referer':'www.google.com' } | |
url = base_url + cve | |
my_session = requests.session() | |
for_cookies = my_session.get(url) | |
cookies = for_cookies.cookies | |
print(url) | |
page = requests.get(url, headers=headers, cookies=cookies) | |
soup = BeautifulSoup(page.text, 'html.parser') | |
tables = soup.find_all('table') | |
tdf = find_table_input_column(tables, "Type") | |
#return tdf | |
if tdf.empty : | |
return "NA" | |
else: | |
if 'NIST' in tdf[tdf.Type.str.contains('V3')]['New Value'].tolist()[0] : | |
vector = tdf[tdf.Type.str.contains('V3')]['New Value'].tolist()[0].split('NIST ')[1] | |
else : | |
vector = tdf[tdf.Type.str.contains('V3')]['New Value'].tolist()[0].split('NIST ')[0] | |
return vector | |
def find_table_input_column(tables,column): | |
for table in tables: | |
try : | |
tdf=parse_html_table (table) | |
if column in tdf.columns: | |
if any("V3" in s for s in tdf.Type.unique().tolist()): | |
print ("v3 in columns") | |
return tdf | |
else: | |
continue | |
except: | |
pass | |
return pd.DataFrame() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment