-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Triwoods2333/main
download_npm
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"e:\\anaconda\\envs\\jut_env\\lib\\site-packages\\scipy\\__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.5\n", | ||
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import warnings\n", | ||
"warnings.filterwarnings('ignore')\n", | ||
"pd.set_option('display.max_columns', None)\n", | ||
"pd.set_option('display.max_rows', None)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 27, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>Package Repository</th>\n", | ||
" <th>Package Name</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>NPM</td>\n", | ||
" <td>URIjs-1.16.1</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" Package Repository Package Name\n", | ||
"0 NPM URIjs-1.16.1" | ||
] | ||
}, | ||
"execution_count": 27, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# 数据读取\n", | ||
"df = pd.read_excel('Labelled_Dataset.xlsx',sheet_name=0)\n", | ||
"# 取前5行查看数据\n", | ||
"df = df.iloc[:1,1:3]\n", | ||
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"URIjs 1.16.1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import subprocess\n", | ||
"import os\n", | ||
"\n", | ||
"# 更新 PATH 环境变量\n", | ||
"os.environ['PATH'] += os.pathsep + 'D:/nodejs'\n", | ||
"\n", | ||
"# 遍历每一行\n", | ||
"for index, row in df.iterrows():\n", | ||
" package_name = row['Package Name']\n", | ||
" # 分割包名和版本号\n", | ||
" name, version = package_name.split('-')\n", | ||
" print(name, version)\n", | ||
" # 使用npm命令行工具下载包\n", | ||
" subprocess.run(['D:/nodejs/npm.cmd', 'pack', f'{name}@{version}'], cwd=r'F:\\git_workspace\\malicious_samples-features-identification\\npm_download')\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "jut_env", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |