박나리

kakaomap crawling

1 +{
2 + "cells": [
3 + {
4 + "cell_type": "code",
5 + "execution_count": 22,
6 + "metadata": {},
7 + "outputs": [
8 + {
9 + "name": "stdout",
10 + "output_type": "stream",
11 + "text": [
12 + "Requirement already satisfied: googlemaps in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (4.6.0)\n",
13 + "Requirement already satisfied: requests<3.0,>=2.20.0 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from googlemaps) (2.24.0)\n",
14 + "Requirement already satisfied: idna<3,>=2.5 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests<3.0,>=2.20.0->googlemaps) (2.10)\n",
15 + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests<3.0,>=2.20.0->googlemaps) (1.22)\n",
16 + "Requirement already satisfied: chardet<4,>=3.0.2 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests<3.0,>=2.20.0->googlemaps) (3.0.4)\n",
17 + "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests<3.0,>=2.20.0->googlemaps) (2020.6.20)\n"
18 + ]
19 + }
20 + ],
21 + "source": [
22 + "%pip install googlemaps"
23 + ]
24 + },
25 + {
26 + "cell_type": "code",
27 + "execution_count": 23,
28 + "metadata": {},
29 + "outputs": [
30 + {
31 + "name": "stdout",
32 + "output_type": "stream",
33 + "text": [
34 + "Requirement already satisfied: folium in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (0.12.1.post1)\n",
35 + "Requirement already satisfied: jinja2>=2.9 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from folium) (2.11.2)\n",
36 + "Requirement already satisfied: branca>=0.3.0 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from folium) (0.5.0)\n",
37 + "Requirement already satisfied: numpy in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from folium) (1.22.4)\n",
38 + "Requirement already satisfied: requests in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from folium) (2.24.0)\n",
39 + "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from jinja2>=2.9->folium) (1.1.1)\n",
40 + "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests->folium) (2020.6.20)\n",
41 + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests->folium) (1.22)\n",
42 + "Requirement already satisfied: chardet<4,>=3.0.2 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests->folium) (3.0.4)\n",
43 + "Requirement already satisfied: idna<3,>=2.5 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from requests->folium) (2.10)\n"
44 + ]
45 + }
46 + ],
47 + "source": [
48 + "%pip install folium"
49 + ]
50 + },
51 + {
52 + "cell_type": "code",
53 + "execution_count": 24,
54 + "metadata": {},
55 + "outputs": [
56 + {
57 + "name": "stdout",
58 + "output_type": "stream",
59 + "text": [
60 + "Requirement already satisfied: selenium in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (4.2.0)\n",
61 + "Requirement already satisfied: trio-websocket~=0.9 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from selenium) (0.9.2)\n",
62 + "Requirement already satisfied: trio~=0.17 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from selenium) (0.20.0)\n",
63 + "Collecting urllib3[secure,socks]~=1.26\n",
64 + " Using cached urllib3-1.26.9-py2.py3-none-any.whl (138 kB)\n",
65 + "Requirement already satisfied: async-generator>=1.9 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (1.10)\n",
66 + "Requirement already satisfied: cffi>=1.14 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (1.14.3)\n",
67 + "Requirement already satisfied: idna in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (2.10)\n",
68 + "Requirement already satisfied: sniffio in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (1.2.0)\n",
69 + "Requirement already satisfied: outcome in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (1.1.0)\n",
70 + "Requirement already satisfied: attrs>=19.2.0 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (20.3.0)\n",
71 + "Requirement already satisfied: sortedcontainers in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio~=0.17->selenium) (2.2.2)\n",
72 + "Requirement already satisfied: wsproto>=0.14 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from trio-websocket~=0.9->selenium) (1.1.0)\n",
73 + "Requirement already satisfied: PySocks!=1.5.7,<2.0,>=1.5.6 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from urllib3[secure,socks]~=1.26->selenium) (1.7.1)\n",
74 + "Requirement already satisfied: pyOpenSSL>=0.14 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from urllib3[secure,socks]~=1.26->selenium) (19.1.0)\n",
75 + "Requirement already satisfied: cryptography>=1.3.4 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from urllib3[secure,socks]~=1.26->selenium) (3.1.1)\n",
76 + "Requirement already satisfied: certifi in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from urllib3[secure,socks]~=1.26->selenium) (2020.6.20)\n",
77 + "Requirement already satisfied: pycparser in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from cffi>=1.14->trio~=0.17->selenium) (2.20)\n",
78 + "Requirement already satisfied: six>=1.4.1 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from cryptography>=1.3.4->urllib3[secure,socks]~=1.26->selenium) (1.15.0)\n",
79 + "Requirement already satisfied: h11<1,>=0.9.0 in c:\\users\\pnr02\\anaconda3\\lib\\site-packages (from wsproto>=0.14->trio-websocket~=0.9->selenium) (0.13.0)\n",
80 + "Installing collected packages: urllib3\n",
81 + " Attempting uninstall: urllib3\n",
82 + " Found existing installation: urllib3 1.22\n",
83 + " Uninstalling urllib3-1.22:\n",
84 + " Successfully uninstalled urllib3-1.22\n",
85 + "Successfully installed urllib3-1.26.9\n"
86 + ]
87 + },
88 + {
89 + "name": "stderr",
90 + "output_type": "stream",
91 + "text": [
92 + "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
93 + "requests 2.24.0 requires urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1, but you have urllib3 1.26.9 which is incompatible.\n"
94 + ]
95 + }
96 + ],
97 + "source": [
98 + "%pip install selenium"
99 + ]
100 + },
101 + {
102 + "cell_type": "code",
103 + "execution_count": 25,
104 + "metadata": {},
105 + "outputs": [
106 + {
107 + "name": "stdout",
108 + "output_type": "stream",
109 + "text": [
110 + "Collecting urllib3==1.22\n",
111 + " Using cached urllib3-1.22-py2.py3-none-any.whl (132 kB)\n",
112 + "Installing collected packages: urllib3\n",
113 + " Attempting uninstall: urllib3\n",
114 + " Found existing installation: urllib3 1.26.9\n",
115 + " Uninstalling urllib3-1.26.9:\n",
116 + " Successfully uninstalled urllib3-1.26.9\n",
117 + "Successfully installed urllib3-1.22\n"
118 + ]
119 + },
120 + {
121 + "name": "stderr",
122 + "output_type": "stream",
123 + "text": [
124 + "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
125 + "selenium 4.2.0 requires urllib3[secure,socks]~=1.26, but you have urllib3 1.22 which is incompatible.\n"
126 + ]
127 + }
128 + ],
129 + "source": [
130 + "%pip install urllib3==1.22"
131 + ]
132 + },
133 + {
134 + "cell_type": "code",
135 + "execution_count": 35,
136 + "metadata": {},
137 + "outputs": [
138 + {
139 + "name": "stderr",
140 + "output_type": "stream",
141 + "text": [
142 + "<ipython-input-35-8eb54e3817f4>:28: DeprecationWarning: executable_path has been deprecated, please pass in a Service object\n",
143 + " driver = webdriver.Chrome(os.path.join(os.getcwd(), chromedriver_path), options=options)\n"
144 + ]
145 + },
146 + {
147 + "name": "stdout",
148 + "output_type": "stream",
149 + "text": [
150 + "찾고싶은 음식종류서울 한식집\n",
151 + "파일이름: 영어로치기SeoulKor\n"
152 + ]
153 + }
154 + ],
155 + "source": [
156 + "import time\n",
157 + "import os\n",
158 + "from selenium import webdriver\n",
159 + "from selenium.webdriver.common.keys import Keys\n",
160 + "\n",
161 + "import requests\n",
162 + "import csv\n",
163 + "import urllib.request\n",
164 + "import urllib.parse\n",
165 + "import re\n",
166 + "from bs4 import BeautifulSoup\n",
167 + "\n",
168 + "headers = {\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36\"}\n",
169 + "\n",
170 + "\n",
171 + "list = []\n",
172 + "\n",
173 + "url = \"https://map.kakao.com/\"\n",
174 + "\n",
175 + "options = webdriver.ChromeOptions()\n",
176 + "\n",
177 + "options = webdriver.ChromeOptions()\n",
178 + "\n",
179 + "options.add_argument('lang=ko_KR')\n",
180 + "\n",
181 + "chromedriver_path = \"chromedriver\"\n",
182 + "\n",
183 + "driver = webdriver.Chrome(os.path.join(os.getcwd(), chromedriver_path), options=options)\n",
184 + "\n",
185 + "\n",
186 + "driver.get(url)\n",
187 + "\n",
188 + "searchloc = input(\"찾고싶은 음식종류\")\n",
189 + "\n",
190 + "filename = input(\"파일이름: 영어로치기\")"
191 + ]
192 + },
193 + {
194 + "cell_type": "code",
195 + "execution_count": 34,
196 + "metadata": {},
197 + "outputs": [
198 + {
199 + "name": "stderr",
200 + "output_type": "stream",
201 + "text": [
202 + "<ipython-input-34-45a7f2f9dddb>:1: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead\n",
203 + " search_area = driver.find_element_by_xpath('//*[@id=\"search.keyword.query\"]')\n"
204 + ]
205 + },
206 + {
207 + "ename": "KeyboardInterrupt",
208 + "evalue": "",
209 + "output_type": "error",
210 + "traceback": [
211 + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
212 + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
213 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 379\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# Python 2.7, use buffering of HTTP responses\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 380\u001b[1;33m \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbuffering\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 381\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
214 + "\u001b[1;31mTypeError\u001b[0m: getresponse() got an unexpected keyword argument 'buffering'",
215 + "\nDuring handling of the above exception, another exception occurred:\n",
216 + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
217 + "\u001b[1;32m<ipython-input-34-45a7f2f9dddb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msearch_area\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind_element_by_xpath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'//*[@id=\"search.keyword.query\"]'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0msearch_area\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend_keys\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msearchloc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind_element_by_xpath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'//*[@id=\"search.keyword.submit\"]'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend_keys\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mKeys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mENTER\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
218 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mfind_element_by_xpath\u001b[1;34m(self, xpath)\u001b[0m\n\u001b[0;32m 524\u001b[0m \u001b[0mstacklevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 525\u001b[0m )\n\u001b[1;32m--> 526\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind_element\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mby\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mBy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mXPATH\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mxpath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 527\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 528\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfind_elements_by_xpath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mxpath\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[0mList\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mWebElement\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
219 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mfind_element\u001b[1;34m(self, by, value)\u001b[0m\n\u001b[0;32m 1249\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'[name=\"%s\"]'\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1250\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1251\u001b[1;33m return self.execute(Command.FIND_ELEMENT, {\n\u001b[0m\u001b[0;32m 1252\u001b[0m \u001b[1;34m'using'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mby\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1253\u001b[0m 'value': value})['value']\n",
220 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, driver_command, params)\u001b[0m\n\u001b[0;32m 426\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 427\u001b[0m \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_wrap_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 428\u001b[1;33m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 429\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 430\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
221 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, command, params)\u001b[0m\n\u001b[0;32m 345\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mutils\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdump_json\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 346\u001b[0m \u001b[0murl\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf\"{self._url}{path}\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 347\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_request\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommand_info\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 348\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 349\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_request\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
222 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py\u001b[0m in \u001b[0;36m_request\u001b[1;34m(self, method, url, body)\u001b[0m\n\u001b[0;32m 367\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 368\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeep_alive\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 369\u001b[1;33m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_conn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 370\u001b[0m \u001b[0mstatuscode\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstatus\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 371\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
223 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\request.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, fields, headers, **urlopen_kw)\u001b[0m\n\u001b[0;32m 66\u001b[0m **urlopen_kw)\n\u001b[0;32m 67\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 68\u001b[1;33m return self.request_encode_body(method, url, fields=fields,\n\u001b[0m\u001b[0;32m 69\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 70\u001b[0m **urlopen_kw)\n",
224 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\request.py\u001b[0m in \u001b[0;36mrequest_encode_body\u001b[1;34m(self, method, url, fields, headers, encode_multipart, multipart_boundary, **urlopen_kw)\u001b[0m\n\u001b[0;32m 146\u001b[0m \u001b[0mextra_kw\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murlopen_kw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 147\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 148\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0murlopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mextra_kw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
225 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\poolmanager.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, redirect, **kw)\u001b[0m\n\u001b[0;32m 319\u001b[0m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0murlopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 321\u001b[1;33m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0murlopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mu\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest_uri\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 322\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 323\u001b[0m \u001b[0mredirect_location\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mredirect\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_redirect_location\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
226 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 596\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 597\u001b[0m \u001b[1;31m# Make the request on the httplib connection object.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 598\u001b[1;33m httplib_response = self._make_request(conn, method, url,\n\u001b[0m\u001b[0;32m 599\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout_obj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 600\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
227 + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 381\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 382\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 383\u001b[1;33m \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 384\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 385\u001b[0m \u001b[1;31m# Remove the TypeError from the exception chain in Python 3;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
228 + "\u001b[1;32m~\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mgetresponse\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1345\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1346\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1347\u001b[1;33m \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbegin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1348\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mConnectionError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1349\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
229 + "\u001b[1;32m~\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mbegin\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 305\u001b[0m \u001b[1;31m# read until we get a non-100 response\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 306\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 307\u001b[1;33m \u001b[0mversion\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreason\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 308\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mstatus\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mCONTINUE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 309\u001b[0m \u001b[1;32mbreak\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
230 + "\u001b[1;32m~\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_read_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 266\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 267\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 268\u001b[1;33m \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_MAXLINE\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"iso-8859-1\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 269\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0m_MAXLINE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 270\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mLineTooLong\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"status line\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
231 + "\u001b[1;32m~\\anaconda3\\lib\\socket.py\u001b[0m in \u001b[0;36mreadinto\u001b[1;34m(self, b)\u001b[0m\n\u001b[0;32m 667\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 668\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 669\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 670\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 671\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_timeout_occurred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
232 + "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
233 + ]
234 + }
235 + ],
236 + "source": [
237 + "search_area = driver.find_element_by_xpath('//*[@id=\"search.keyword.query\"]')\n",
238 + "search_area.send_keys(searchloc)\n",
239 + "driver.find_element_by_xpath('//*[@id=\"search.keyword.submit\"]').send_keys(Keys.ENTER)\n",
240 + "\n",
241 + "time.sleep(2)\n",
242 + "\n",
243 + "driver.find_element_by_xpath('//*[@id=\"info.main.options\"]/li[2]/a').send_keys(Keys.ENTER)"
244 + ]
245 + },
246 + {
247 + "cell_type": "code",
248 + "execution_count": 29,
249 + "metadata": {},
250 + "outputs": [],
251 + "source": [
252 + "def storeNamePrint():\n",
253 + " \n",
254 + " time.sleep(0.2)\n",
255 + " \n",
256 + " html = driver.page_source\n",
257 + " soup = BeautifulSoup(html, 'html.parser')\n",
258 + " \n",
259 + " cafe_lists = soup.select('.placelist > .PlaceItem')\n",
260 + " count =1\n",
261 + " for cafe in cafe_lists:\n",
262 + " \n",
263 + " temp=[]\n",
264 + " cafe_name = cafe.select('.head_item > .tit_name > .link_name')[0].text\n",
265 + " food_score = cafe.select('.rating > .score > .num')[0].text\n",
266 + " review = cafe.select('.rating > .review')[0].text\n",
267 + " link = cafe.select('.contact > .moreview' )[0]['href']\n",
268 + " addr = cafe.select('.addr')[0].text\n",
269 + " \n",
270 + " \n",
271 + " review= review[3:len(review)]\n",
272 + " \n",
273 + " review = int(re.sub(\",\",\"\",review))\n",
274 + " \n",
275 + " print(cafe_name, food_score, review, link, addr)\n",
276 + " \n",
277 + " temp.append(cafe_name)\n",
278 + " temp.append(food_score)\n",
279 + " temp.append(review)\n",
280 + " temp.append(link)\n",
281 + " temp.append(addr)\n",
282 + " \n",
283 + " list.append(temp)\n",
284 + " \n",
285 + " f=open(filename+'.csv', \"w\", encoding=\"utf-8-sig\",newline=\"\")\n",
286 + " writercsv=csv.writer(f)\n",
287 + " header=['Name', 'Score', 'Review', 'Link', 'Addr']\n",
288 + " writercsv.writerow(header)\n",
289 + " \n",
290 + " for i in list:\n",
291 + " writercsv.writerow(i)"
292 + ]
293 + },
294 + {
295 + "cell_type": "code",
296 + "execution_count": 45,
297 + "metadata": {},
298 + "outputs": [
299 + {
300 + "name": "stdout",
301 + "output_type": "stream",
302 + "text": [
303 + "** 1 **\n"
304 + ]
305 + },
306 + {
307 + "name": "stderr",
308 + "output_type": "stream",
309 + "text": [
310 + "<ipython-input-45-c53d51277e5a>:10: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead\n",
311 + " driver.find_element_by_xpath(f'//*[@id=\"info.search.page.no{page2}\"]').send_keys(Keys.ENTER)\n"
312 + ]
313 + },
314 + {
315 + "name": "stdout",
316 + "output_type": "stream",
317 + "text": [
318 + "진대감 신사점 4.2 62 https://place.map.kakao.com/17678577 \n",
319 + "서울 서초구 나루터로12길 18\n",
320 + "(지번) 잠원동 23-8\n",
321 + "\n",
322 + "이한진숙성회 4.1 129 https://place.map.kakao.com/1010304045 \n",
323 + "서울 강동구 구천면로 247-1 2층\n",
324 + "(지번) 천호동 393-15\n",
325 + "\n",
326 + "무식당 2.3 99 https://place.map.kakao.com/2144202741 \n",
327 + "서울 성동구 왕십리로10길 5-9\n",
328 + "(지번) 성수동1가 656-1042\n",
329 + "\n",
330 + "필녀의한정식 3.3 433 https://place.map.kakao.com/26848979 \n",
331 + "서울 송파구 동남로 308\n",
332 + "(지번) 오금동 129-24\n",
333 + "\n",
334 + "제주도그릴 특상본점 3.3 92 https://place.map.kakao.com/26541520 \n",
335 + "서울 은평구 응암로 373 역촌빌딩 1층\n",
336 + "(지번) 녹번동 161-5\n",
337 + "\n",
338 + "조가네갑오징어 사당직영3호점 3.3 94 https://place.map.kakao.com/21827385 \n",
339 + "서울 동작구 남부순환로271길 24\n",
340 + "(지번) 사당동 1041-5\n",
341 + "\n",
342 + "강고집 사당본점 4.6 123 https://place.map.kakao.com/736976770 \n",
343 + "서울 서초구 방배천로4안길 6 1층\n",
344 + "(지번) 방배동 451-7\n",
345 + "\n",
346 + "편안한집 3.6 26 https://place.map.kakao.com/8578960 \n",
347 + "서울 종로구 북촌로 133\n",
348 + "(지번) 삼청동 27-3\n",
349 + "\n",
350 + "육장 4.0 158 https://place.map.kakao.com/64633006 \n",
351 + "서울 마포구 월드컵로19길 74 지하2층\n",
352 + "(지번) 망원동 57-194\n",
353 + "\n",
354 + "능이버섯백숙 4.2 61 https://place.map.kakao.com/11279164 \n",
355 + "서울 영등포구 선유로 32\n",
356 + "(지번) 문래동4가 9-2\n",
357 + "\n",
358 + "박순례손말이고기 산정집 광화문점 2.7 157 https://place.map.kakao.com/27386457 \n",
359 + "서울 종로구 새문안로5가길 3-10 선덕빌딩 2층\n",
360 + "(지번) 당주동 3-2\n",
361 + "\n",
362 + "색동저고리 마포점 3.5 63 https://place.map.kakao.com/18582704 \n",
363 + "서울 마포구 도화길 27 2층\n",
364 + "(지번) 도화동 179-3\n",
365 + "\n",
366 + "갈비생각 발산점 3.8 122 https://place.map.kakao.com/617688288 \n",
367 + "서울 강서구 강서로54길 42 1층\n",
368 + "(지번) 등촌동 672\n",
369 + "\n",
370 + "주은감자탕 2.3 142 https://place.map.kakao.com/9427365 \n",
371 + "서울 송파구 삼학사로 71 1층\n",
372 + "(지번) 삼전동 132-14\n",
373 + "\n",
374 + "경주식당 3.6 172 https://place.map.kakao.com/27315733 \n",
375 + "서울 마포구 와우산로13길 49-7\n",
376 + "(지번) 상수동 314-10\n",
377 + "\n",
378 + "**크롤링완료**\n"
379 + ]
380 + }
381 + ],
382 + "source": [
383 + "page =1\n",
384 + "page2=0\n",
385 + "\n",
386 + "for i in range(0,34):\n",
387 + " \n",
388 + " try:\n",
389 + " page2+=1\n",
390 + " print(\"**\",page,\"**\")\n",
391 + " \n",
392 + " driver.find_element_by_xpath(f'//*[@id=\"info.search.page.no{page2}\"]').send_keys(Keys.ENTER)\n",
393 + " storeNamePrint()\n",
394 + " \n",
395 + " if (page2)%5==0:\n",
396 + " driver.find_element_by_xpath('//*[@id=\"info.search.page.next\"]').send_keys(Keys.ENTER)\n",
397 + " page2=0\n",
398 + " \n",
399 + " page+=1\n",
400 + " \n",
401 + " except:\n",
402 + " break\n",
403 + " \n",
404 + "print(\"**크롤링완료**\")"
405 + ]
406 + },
407 + {
408 + "cell_type": "code",
409 + "execution_count": 46,
410 + "metadata": {},
411 + "outputs": [],
412 + "source": [
413 + "import googlemaps\n",
414 + "import pandas as pd\n",
415 + "df_list=pd.read_csv(filename+'.csv',encoding='utf-8')\n",
416 + "\n",
417 + "gmaps_key = \"AIzaSyCI8potusd7KjsX-aGXX4jWMKWBoiop1jY\"\n",
418 + "gmaps = googlemaps.Client(key = gmaps_key)\n"
419 + ]
420 + },
421 + {
422 + "cell_type": "code",
423 + "execution_count": 48,
424 + "metadata": {},
425 + "outputs": [
426 + {
427 + "name": "stdout",
428 + "output_type": "stream",
429 + "text": [
430 + "위경도 추가 완료\n"
431 + ]
432 + },
433 + {
434 + "data": {
435 + "text/html": [
436 + "<div>\n",
437 + "<style scoped>\n",
438 + " .dataframe tbody tr th:only-of-type {\n",
439 + " vertical-align: middle;\n",
440 + " }\n",
441 + "\n",
442 + " .dataframe tbody tr th {\n",
443 + " vertical-align: top;\n",
444 + " }\n",
445 + "\n",
446 + " .dataframe thead th {\n",
447 + " text-align: right;\n",
448 + " }\n",
449 + "</style>\n",
450 + "<table border=\"1\" class=\"dataframe\">\n",
451 + " <thead>\n",
452 + " <tr style=\"text-align: right;\">\n",
453 + " <th></th>\n",
454 + " <th>Name</th>\n",
455 + " <th>Score</th>\n",
456 + " <th>Review</th>\n",
457 + " <th>Link</th>\n",
458 + " <th>Addr</th>\n",
459 + " <th>lat</th>\n",
460 + " <th>lng</th>\n",
461 + " </tr>\n",
462 + " </thead>\n",
463 + " <tbody>\n",
464 + " <tr>\n",
465 + " <th>496</th>\n",
466 + " <td>광주식당</td>\n",
467 + " <td>3.3</td>\n",
468 + " <td>105</td>\n",
469 + " <td>https://place.map.kakao.com/18829150</td>\n",
470 + " <td>\\n서울 동대문구 경동시장로2길 49-4\\n(지번) 청량리동 773\\n</td>\n",
471 + " <td>37.580570</td>\n",
472 + " <td>127.043681</td>\n",
473 + " </tr>\n",
474 + " <tr>\n",
475 + " <th>497</th>\n",
476 + " <td>호반</td>\n",
477 + " <td>4.0</td>\n",
478 + " <td>99</td>\n",
479 + " <td>https://place.map.kakao.com/27269590</td>\n",
480 + " <td>\\n서울 종로구 삼일대로26길 20\\n(지번) 낙원동 85-7\\n</td>\n",
481 + " <td>37.573264</td>\n",
482 + " <td>126.989129</td>\n",
483 + " </tr>\n",
484 + " <tr>\n",
485 + " <th>498</th>\n",
486 + " <td>신흥정육식당</td>\n",
487 + " <td>3.4</td>\n",
488 + " <td>72</td>\n",
489 + " <td>https://place.map.kakao.com/21401480</td>\n",
490 + " <td>\\n서울 강동구 양재대로89길 16\\n(지번) 성내동 428-2\\n</td>\n",
491 + " <td>37.526853</td>\n",
492 + " <td>127.134672</td>\n",
493 + " </tr>\n",
494 + " <tr>\n",
495 + " <th>499</th>\n",
496 + " <td>백억하누 강남본점</td>\n",
497 + " <td>4.8</td>\n",
498 + " <td>151</td>\n",
499 + " <td>https://place.map.kakao.com/26431943</td>\n",
500 + " <td>\\n서울 강남구 테헤란로5길 29\\n(지번) 역삼동 817-26\\n</td>\n",
501 + " <td>37.500464</td>\n",
502 + " <td>127.028756</td>\n",
503 + " </tr>\n",
504 + " <tr>\n",
505 + " <th>500</th>\n",
506 + " <td>계탄집 본점</td>\n",
507 + " <td>4.4</td>\n",
508 + " <td>111</td>\n",
509 + " <td>https://place.map.kakao.com/26941179</td>\n",
510 + " <td>\\n서울 광진구 능동로 31 1층\\n(지번) 자양동 553-264\\n</td>\n",
511 + " <td>37.534207</td>\n",
512 + " <td>127.067711</td>\n",
513 + " </tr>\n",
514 + " </tbody>\n",
515 + "</table>\n",
516 + "</div>"
517 + ],
518 + "text/plain": [
519 + " Name Score Review Link \\\n",
520 + "496 광주식당 3.3 105 https://place.map.kakao.com/18829150 \n",
521 + "497 호반 4.0 99 https://place.map.kakao.com/27269590 \n",
522 + "498 신흥정육식당 3.4 72 https://place.map.kakao.com/21401480 \n",
523 + "499 백억하누 강남본점 4.8 151 https://place.map.kakao.com/26431943 \n",
524 + "500 계탄집 본점 4.4 111 https://place.map.kakao.com/26941179 \n",
525 + "\n",
526 + " Addr lat lng \n",
527 + "496 \\n서울 동대문구 경동시장로2길 49-4\\n(지번) 청량리동 773\\n 37.580570 127.043681 \n",
528 + "497 \\n서울 종로구 삼일대로26길 20\\n(지번) 낙원동 85-7\\n 37.573264 126.989129 \n",
529 + "498 \\n서울 강동구 양재대로89길 16\\n(지번) 성내동 428-2\\n 37.526853 127.134672 \n",
530 + "499 \\n서울 강남구 테헤란로5길 29\\n(지번) 역삼동 817-26\\n 37.500464 127.028756 \n",
531 + "500 \\n서울 광진구 능동로 31 1층\\n(지번) 자양동 553-264\\n 37.534207 127.067711 "
532 + ]
533 + },
534 + "execution_count": 48,
535 + "metadata": {},
536 + "output_type": "execute_result"
537 + }
538 + ],
539 + "source": [
540 + "place_lat = []\n",
541 + "place_lng = []\n",
542 + "\n",
543 + "max_lat = 38.0\n",
544 + "min_lat = 33.0\n",
545 + "max_lng = 132.0\n",
546 + "min_lng = 126.0\n",
547 + "\n",
548 + "\n",
549 + "for place in df_list[\"Addr\"]:\n",
550 + " tmp = gmaps.geocode(place, language = \"ko\")\n",
551 + " \n",
552 + " if tmp:\n",
553 + " tmp_loc = tmp[0].get(\"geometry\")\n",
554 + " tmp_lat = tmp_loc[\"location\"][\"lat\"]\n",
555 + " tmp_lng = tmp_loc[\"location\"][\"lng\"]\n",
556 + " \n",
557 + " if(tmp_lat > max_lat or tmp_lat < min_lat or tmp_lng > max_lng or tmp_lng < min_lng):\n",
558 + " place_lat.append(\"0\")\n",
559 + " place_lng.append(\"0\")\n",
560 + " \n",
561 + " \n",
562 + " else:\n",
563 + " place_lat.append(tmp_lat)\n",
564 + " place_lng.append(tmp_lng)\n",
565 + " \n",
566 + " else:\n",
567 + " place_lat.append(\"0\")\n",
568 + " place_lng.append(\"0\")\n",
569 + " \n",
570 + "print(\"위경도 추가 완료\")\n",
571 + "\n",
572 + "\n",
573 + "df_list2 = pd.DataFrame(place_lat)\n",
574 + "df_list2 = df_list2.rename(columns = {0: \"lat\"})\n",
575 + "df_list3 = pd.DataFrame(place_lng)\n",
576 + "df_list3 = df_list3.rename(columns = {0: \"lng\"})\n",
577 + "\n",
578 + "\n",
579 + "df = pd.concat([df_list, df_list2, df_list3], axis = 1)\n",
580 + "\n",
581 + "df = df.query(\"lat != '0'\")\n",
582 + "\n",
583 + "df.to_csv(filename+\"location.csv\", encoding = \"utf-8-sig\")\n",
584 + "\n",
585 + "df.tail()"
586 + ]
587 + },
588 + {
589 + "cell_type": "code",
590 + "execution_count": 55,
591 + "metadata": {},
592 + "outputs": [
593 + {
594 + "data": {
595 + "text/plain": [
596 + "'계탄집 본점<br> 평점 : 4.4<br> 리뷰수 : 111<br> 주소 : \\n서울 광진구 능동로 31 1층\\n(지번) 자양동 553-264\\n<br><a href=\"https://place.map.kakao.com/26941179\" target=\"_self\">https://place.map.kakao.com/26941179</a>'"
597 + ]
598 + },
599 + "execution_count": 55,
600 + "metadata": {},
601 + "output_type": "execute_result"
602 + }
603 + ],
604 + "source": [
605 + "import pandas as pd\n",
606 + "import folium\n",
607 + "import webbrowser\n",
608 + "from folium.plugins import MarkerCluster\n",
609 + "\n",
610 + "data_frame = pd.read_csv(filename+ \"location.csv\", encoding='utf-8')\n",
611 + "\n",
612 + "data_frame\n",
613 + "\n",
614 + "map = folium.Map(location = [35.8797296, 128.4964884], zoom_start =7)\n",
615 + "\n",
616 + "marker_cluster = MarkerCluster().add_to(map)\n",
617 + "\n",
618 + "\n",
619 + "for index,a in data_frame.iterrows():\n",
620 + " \n",
621 + " \n",
622 + " if float(a[\"Score\"]) >=4:\n",
623 + " \n",
624 + " score_color = \"red\"\n",
625 + " \n",
626 + " \n",
627 + " elif float(a[\"Score\"]) >=3:\n",
628 + " \n",
629 + " score_color = \"orange\"\n",
630 + " \n",
631 + " \n",
632 + " else:\n",
633 + " \n",
634 + " score_color = \"lightgreen\"\n",
635 + " \n",
636 + " \n",
637 + " print_popup= str(a[\"Name\"])+\"<br> 평점 : \"+ str(a[\"Score\"])+ \"<br> 리뷰수 : \"+str(a[\"Review\"])+ \"<br> 주소 : \"+str(a[\"Addr\"])+ \"<br>\"+'<a href=\"'+ str(a[\"Link\"]) + '\" target=\"_self\">'+str(a[\"Link\"])+ '</a>'\n",
638 + " \n",
639 + " \n",
640 + " folium.Marker(location = [a[\"lat\"], a[\"lng\"]],\n",
641 + " \n",
642 + " popup=print_popup, icon=folium.Icon(color=score_color)).add_to(marker_cluster)\n",
643 + " \n",
644 + "map\n",
645 + "\n",
646 + "map.save('selectWestern.html')\n",
647 + "\n",
648 + "\n",
649 + "webbrowser.open('selectWestern.html')\n",
650 + "\n",
651 + "print_popup\n",
652 + " "
653 + ]
654 + },
655 + {
656 + "cell_type": "code",
657 + "execution_count": null,
658 + "metadata": {},
659 + "outputs": [],
660 + "source": []
661 + }
662 + ],
663 + "metadata": {
664 + "kernelspec": {
665 + "display_name": "Python 3",
666 + "language": "python",
667 + "name": "python3"
668 + },
669 + "language_info": {
670 + "codemirror_mode": {
671 + "name": "ipython",
672 + "version": 3
673 + },
674 + "file_extension": ".py",
675 + "mimetype": "text/x-python",
676 + "name": "python",
677 + "nbconvert_exporter": "python",
678 + "pygments_lexer": "ipython3",
679 + "version": "3.8.5"
680 + }
681 + },
682 + "nbformat": 4,
683 + "nbformat_minor": 4
684 +}