Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HarimJ committed Mar 20, 2020
2 parents 4536a5e + d5a434f commit aef0e45
Show file tree
Hide file tree
Showing 3 changed files with 532 additions and 0 deletions.
146 changes: 146 additions & 0 deletions 002. korea_cumulative_data_crwler/KoreaCrawling.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[['2/1', 12, 1, 0, 0],\n",
" ['2/2', 15, 3, 0, 0],\n",
" ['2/3', 15, 0, 0, 0],\n",
" ['2/4', 16, 1, 0, 0],\n",
" ['2/5', 19, 3, 0, 0],\n",
" ['2/6', 23, 4, 0, 1],\n",
" ['2/7', 24, 1, 0, 1],\n",
" ['2/8', 24, 0, 0, 2],\n",
" ['2/9', 27, 3, 0, 3],\n",
" ['2/10', 27, 0, 0, 3],\n",
" ['2/11', 28, 1, 0, 4],\n",
" ['2/12', 28, 0, 0, 4],\n",
" ['2/13', 28, 0, 0, 7],\n",
" ['2/14', 28, 0, 0, 7],\n",
" ['2/15', 28, 0, 0, 9],\n",
" ['2/16', 29, 1, 0, 9],\n",
" ['2/17', 30, 1, 0, 9],\n",
" ['2/18', 31, 1, 0, 10],\n",
" ['2/19', 51, 20, 0, 12],\n",
" ['2/20', 104, 53, 1, 16],\n",
" ['2/21', 204, 100, 2, 16],\n",
" ['2/22', 433, 229, 2, 17],\n",
" ['2/23', 602, 169, 6, 18],\n",
" ['2/24', 833, 231, 8, 18],\n",
" ['2/25', 977, 144, 12, 22],\n",
" ['2/26', 1261, 284, 13, 22],\n",
" ['2/27', 1766, 505, 13, 24],\n",
" ['2/28', 2337, 571, 16, 26],\n",
" ['2/29', 3150, 813, 17, 27],\n",
" ['3/1', 3736, 586, 21, 30],\n",
" ['3/2', 4212, 476, 22, 30],\n",
" ['3/3', 4812, 600, 28, 34],\n",
" ['3/4', 5328, 516, 32, 41],\n",
" ['3/5', 5766, 438, 35, 88],\n",
" ['3/6', 6284, 518, 42, 108],\n",
" ['3/7', 6767, 483, 44, 118],\n",
" ['3/8', 7134, 367, 50, 130],\n",
" ['3/9', 7382, 284, 51, 166],\n",
" ['3/10', 7513, 131, 54, 247],\n",
" ['3/11', 7755, 242, 60, 288],\n",
" ['3/12', 7869, 114, 66, 333],\n",
" ['3/13', 7979, 110, 67, 410],\n",
" ['3/14', 8086, 107, 72, 714],\n",
" ['3/15', 8162, 76, 75, 834],\n",
" ['3/16', 8236, 74, 75, 1137],\n",
" ['3/17', 8320, 158, 81, 1401],\n",
" ['3/18', 8413, 93, 84, 1540],\n",
" ['3/19', 8565, 152, 91, 1947]]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import json\n",
"with open('koreacrawl.js', 'r', encoding='UTF-8-sig') as f:\n",
" data = json.load(f)\n",
"import json\n",
"from datetime import date\n",
"today = date.today()\n",
"day = today.strftime(f\"{today.month}/{today.day}\")\n",
"\n",
"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",
"tables2 = table.find_all(\"td\")\n",
"\n",
"num=[]\n",
"for i in range(0, len(tables2)) :\n",
" a = tables2[i].get_text()\n",
" num.append(a)\n",
"\n",
"before_tot = data[len(data)-1][1]\n",
"today_tot = int(num[0].replace(',',''))\n",
"diff=today_tot - before_tot\n",
"death = int(num[3])\n",
"release = int(num[1].replace(',',''))\n",
"\n",
"now = []\n",
"now.append(day)\n",
"now.append(today_tot)\n",
"now.append(diff)\n",
"now.append(death)\n",
"now.append(release)\n",
"\n",
"if data[len(data)-1][0] == day :\n",
" with open('koreacrawl.js', 'r') as f:\n",
" data = json.load(f)\n",
"else : \n",
" data.append(now)\n",
"\n",
"with open('koreacrawl.js', 'w', encoding='utf-8') as make_file:\n",
" json.dump(data, make_file, indent=\"\\t\")\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}
Loading

0 comments on commit aef0e45

Please sign in to comment.