-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
114 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,114 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"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>확진환자</th>\n", | ||
" <th>격리해제</th>\n", | ||
" <th>격리중</th>\n", | ||
" <th>사망</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>8,413</td>\n", | ||
" <td>1,540</td>\n", | ||
" <td>6,789</td>\n", | ||
" <td>84</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" 확진환자 격리해제 격리중 사망\n", | ||
"0 8,413 1,540 6,789 84" | ||
] | ||
}, | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from bs4 import BeautifulSoup\n", | ||
"from urllib.request import urlopen\n", | ||
"import urllib.request\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"html = urlopen(\"http://ncov.mohw.go.kr/bdBoardList_Real.do?brdId=1&brdGubun=11&ncvContSeq=&contSeq=&board_id=&gubun=\")\n", | ||
"source = html.read()\n", | ||
"html.close()\n", | ||
"\n", | ||
"soup = BeautifulSoup(source, 'lxml')\n", | ||
"table = soup.find(\"div\", class_ = \"data_table mgt16\")\n", | ||
"tables1 = table.find_all(\"th\")\n", | ||
"tables2 = table.find_all(\"td\")\n", | ||
"\n", | ||
"status = []\n", | ||
"for i in range(0,len(tables1)) :\n", | ||
" a = tables1[i].get_text()\n", | ||
" status.append(a)\n", | ||
"\n", | ||
"num=[]\n", | ||
"for i in range(0, len(tables2)) :\n", | ||
" a = tables2[i].get_text()\n", | ||
" num.append(a)\n", | ||
"\n", | ||
"tot = []\n", | ||
"tot.append(num)\n", | ||
"tot = pd.DataFrame(tot)\n", | ||
"\n", | ||
"tot.rename(columns={tot.columns[0] : status[0],\n", | ||
" tot.columns[1] : status[1],\n", | ||
" tot.columns[2] : status[2],\n", | ||
" tot.columns[3] : status[3]})" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |