{"id":8413,"date":"2019-10-01T07:15:25","date_gmt":"2019-09-30T22:15:25","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=8413"},"modified":"2020-01-01T11:14:01","modified_gmt":"2020-01-01T02:14:01","slug":"%eb%84%a4%ec%9d%b4%eb%b2%84-%ec%a3%bc%ec%8b%9d-%ec%84%9c%eb%b9%84%ec%8a%a4%eb%a1%9c%eb%b6%80%ed%84%b0-%ec%a2%85%eb%aa%a9-%ec%8b%9c%ea%b0%80-%ec%a2%85%ea%b0%80-%ea%b3%a0%ea%b0%80-%ec%a0%80%ea%b0%80","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=8413","title":{"rendered":"\ub124\uc774\ubc84 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub85c\ubd80\ud130 \uc885\ubaa9 \uc2dc\uac00, \uc885\uac00, \uace0\uac00, \uc800\uac00, \uac70\ub798\ub7c9, \uc804\uc77c\ub300\ube44\uc5d0 \ub300\ud55c \uc2dc\uacc4\uc5f4 \ub370\uc774\ud130 \uc5bb\uae30"},"content":{"rendered":"<p>\uc8fc\uc2dd \uc885\ubaa9\uc5d0 \ub300\ud55c \ud558\ub8e8 \ub2e8\uc704\uc758 \uc2dc\uac00, \uc885\uac00, \uac70\ub798\ub7c9 \ub4f1\uc744 \uc6f9\uc744 \ud1b5\ud574 \uc5bb\uc744 \uc218 \uc788\ub294\ub370\uc694. \uc774\ub7ec\ud55c \ub370\uc774\ud130\ub97c \ud30c\uc774\uc36c\uc744 \uc774\uc6a9\ud574, \ub124\uc774\ubc84\uc758 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub85c\ubd80\ud130 \uc5bb\ub294 \ucf54\ub4dc\uc5d0 \ub300\ud574 \uc124\uba85\ud569\ub2c8\ub2e4.<\/p>\n<p>\ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. \uc6d0\ud558\ub294 \uc885\ubaa9\uc5d0 \ub300\ud574 \uc6d0\ud558\ub294 \ud398\uc774\uc9c0\ub9cc\ud07c.. (\uc774 \ubd80\ubd84\uc740 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub9c8\ub2e4 \uac00\ub2a5 \uc5ec\ubd80 \ubc0f \ubc29\uc2dd\uc774 \ub2ec\ub77c\uc9d0) \uc815\ubcf4\ub97c \uc5bb\uc5b4\uc635\ub2c8\ub2e4.<\/p>\n<pre class='lang:python'>\r\nimport requests\r\nfrom bs4 import BeautifulSoup\r\n\r\ndef print_stock_price(code, page_num):\r\n    result = [[], [], [], [], [], [], [], [], []]\r\n\r\n    for n in range(page_num):\r\n        url = 'https:\/\/finance.naver.com\/item\/sise_day.nhn?code='+code+'&page='+str(n+1)\r\n        print(url)\r\n\r\n        r = requests.get(url)\r\n\r\n        if not r.ok: \r\n            print('Not more data !')\r\n            break\r\n\r\n        html = r.content\r\n        soup = BeautifulSoup(html, 'html.parser')\r\n        tr = soup.select('table > tr')\r\n\r\n        for i in range(1, len(tr)-1):\r\n            td = tr[i].select('td')\r\n            if td[0].text.strip():\r\n                result[0].append(td[0].text.strip()) # \ub0a0\uc9dc\r\n                result[1].append(td[1].text.strip()) # \uc885\uac00\r\n                \r\n                img = td[2].select('img')\r\n                if len(img) != 0: \r\n                    if 'src' in img[0].attrs:\r\n                        src = img[0]['src']\r\n                        if 'up' in src: result[2].append('\uc0c1\uc2b9')\r\n                        else: result[2].append('\ud558\ub77d')\r\n                else: result[2].append('\ubcf4\ud569')\r\n\r\n                result[3].append(td[2].text.strip()) # \uc804\uc77c\ub300\ube44\r\n                result[4].append(td[3].text.strip()) # \uc2dc\uc7a5\uac00\r\n                result[5].append(td[4].text.strip()) # \ucd5c\uace0\uac00\r\n                result[6].append(td[5].text.strip()) # \ucd5c\uc800\uac00\r\n                result[7].append(td[6].text.strip()) # \uac70\ub798\ub7c9\r\n\r\n    for i in range(len(result[0])):\r\n        #     \ub0a0\uc9dc          \uc885\uac00           \uc0c1\uc2b9\/\ud558\ub77d\/\ubcf4\ud569+a           \uc2dc\uc7a5\uac00         \ucd5c\uace0\uac00        \ucd5c\uc800\uac00        \uac70\ub798\ub7c9\r\n        print(result[0][i], result[1][i], result[2][i]+result[3][i], result[4][i], result[5][i], result[6][i], result[7][i])\r\n\r\nprint_stock_price(code='005930', page_num=1)\r\n<\/pre>\n<p>\ucf54\ub4dc\ub97c \ubcf4\uba74, print_stock_price \ud568\uc218\uc758 url \ubcc0\uc218\uc5d0 \uc800\uc7a5\ub41c \uc8fc\uc18c\uc5d0 \ub300\ud55c \uacb0\uacfc DOM\uc744 \ud574\uc11d\ud558\uace0 \uc788\ub294 \uac83\uc744 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc989, DOM\uc5d0 \ub300\ud55c \uad6c\uc870\ub97c \uba3c\uc800 \ud30c\uc545\ud574\uc57c \ud55c\ub2e4\ub294 \uac83\uc774 \ud575\uc2ec\uc778\ub370\uc694. \uc704\uc758 \ucf54\ub4dc\uac00 \uc815\uc0c1\uc801\uc73c\ub85c \uc791\ub3d9\ud560 \ub2f9\uc2dc\uc758 \uc2e4\uc81c DOM\uc758 \ud55c\uac00\uc9c0 \uc608\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/11\/soup_dom.png\" alt=\"\" width=\"2027\" height=\"1135\" class=\"aligncenter size-full wp-image-8480\" \/><\/p>\n<p>\ucf54\ub4dc\uc640 \ucd94\ucd9c\ud558\uace0\uc790 \ud558\ub294 DOM \uc694\uc18c\uac00 \uba85\ud655\ud558\uac8c 1:1\ub85c \ub9e4\uce6d\ub418\uace0 \uc788\ub294 \uac83\uc744 \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc8fc\uc2dd \uc885\ubaa9\uc5d0 \ub300\ud55c \ud558\ub8e8 \ub2e8\uc704\uc758 \uc2dc\uac00, \uc885\uac00, \uac70\ub798\ub7c9 \ub4f1\uc744 \uc6f9\uc744 \ud1b5\ud574 \uc5bb\uc744 \uc218 \uc788\ub294\ub370\uc694. \uc774\ub7ec\ud55c \ub370\uc774\ud130\ub97c \ud30c\uc774\uc36c\uc744 \uc774\uc6a9\ud574, \ub124\uc774\ubc84\uc758 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub85c\ubd80\ud130 \uc5bb\ub294 \ucf54\ub4dc\uc5d0 \ub300\ud574 \uc124\uba85\ud569\ub2c8\ub2e4. \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. \uc6d0\ud558\ub294 \uc885\ubaa9\uc5d0 \ub300\ud574 \uc6d0\ud558\ub294 \ud398\uc774\uc9c0\ub9cc\ud07c.. (\uc774 \ubd80\ubd84\uc740 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub9c8\ub2e4 \uac00\ub2a5 \uc5ec\ubd80 \ubc0f \ubc29\uc2dd\uc774 \ub2ec\ub77c\uc9d0) \uc815\ubcf4\ub97c \uc5bb\uc5b4\uc635\ub2c8\ub2e4. import requests from bs4 import BeautifulSoup def print_stock_price(code, page_num): result = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=8413\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;\ub124\uc774\ubc84 \uc8fc\uc2dd \uc11c\ube44\uc2a4\ub85c\ubd80\ud130 \uc885\ubaa9 \uc2dc\uac00, \uc885\uac00, \uace0\uac00, \uc800\uac00, \uac70\ub798\ub7c9, \uc804\uc77c\ub300\ube44\uc5d0 \ub300\ud55c \uc2dc\uacc4\uc5f4 \ub370\uc774\ud130 \uc5bb\uae30&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[131],"tags":[],"class_list":["post-8413","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8413"}],"version-history":[{"count":4,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8413\/revisions"}],"predecessor-version":[{"id":8481,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8413\/revisions\/8481"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}