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