Showing
1 changed file
with
119 additions
and
0 deletions
Restaurant_name.ipynb
0 → 100644
1 | +{ | ||
2 | + "cells": [ | ||
3 | + { | ||
4 | + "cell_type": "code", | ||
5 | + "execution_count": null, | ||
6 | + "id": "f383cd9b", | ||
7 | + "metadata": {}, | ||
8 | + "outputs": [], | ||
9 | + "source": [ | ||
10 | + "pip install selenium" | ||
11 | + ] | ||
12 | + }, | ||
13 | + { | ||
14 | + "cell_type": "code", | ||
15 | + "execution_count": 32, | ||
16 | + "id": "65b02eed", | ||
17 | + "metadata": {}, | ||
18 | + "outputs": [ | ||
19 | + { | ||
20 | + "name": "stdout", | ||
21 | + "output_type": "stream", | ||
22 | + "text": [ | ||
23 | + "Requirement already satisfied: lxml in c:\\users\\user\\anaconda3\\lib\\site-packages (4.6.3)\n", | ||
24 | + "Note: you may need to restart the kernel to use updated packages.\n" | ||
25 | + ] | ||
26 | + } | ||
27 | + ], | ||
28 | + "source": [ | ||
29 | + "pip install lxml\n" | ||
30 | + ] | ||
31 | + }, | ||
32 | + { | ||
33 | + "cell_type": "code", | ||
34 | + "execution_count": 12, | ||
35 | + "id": "91a38f02", | ||
36 | + "metadata": {}, | ||
37 | + "outputs": [ | ||
38 | + { | ||
39 | + "name": "stderr", | ||
40 | + "output_type": "stream", | ||
41 | + "text": [ | ||
42 | + "C:\\Users\\User\\AppData\\Local\\Temp/ipykernel_2044/2241818007.py:12: DeprecationWarning: executable_path has been deprecated, please pass in a Service object\n", | ||
43 | + " driver = webdriver.Chrome(\"C:\\\\Users\\\\chromedriver.exe\")\n" | ||
44 | + ] | ||
45 | + }, | ||
46 | + { | ||
47 | + "name": "stdout", | ||
48 | + "output_type": "stream", | ||
49 | + "text": [ | ||
50 | + "['소담촌 수원영통점', '쏘삼돼지208 영통점', '깡우동', '수원의아침', '삿뽀로 영통점', '가보정 영통점', '예랑', '윤가곰탕', '이가네양꼬치 영통점', '아웃백스테이크하우스 수원영통점', '보영만두 영통직영점', '육풍 영통프라임점', '그로또 영통점', '포명천천', '태백한우실비']\n" | ||
51 | + ] | ||
52 | + } | ||
53 | + ], | ||
54 | + "source": [ | ||
55 | + "import requests \n", | ||
56 | + "from bs4 import BeautifulSoup\n", | ||
57 | + "from selenium import webdriver\n", | ||
58 | + "from selenium.webdriver.common.keys import Keys\n", | ||
59 | + "from selenium.webdriver.common.by import By\n", | ||
60 | + "from selenium.webdriver.support.ui import WebDriverWait\n", | ||
61 | + "from selenium.webdriver.support import expected_conditions as EC\n", | ||
62 | + "from time import sleep\n", | ||
63 | + "import pandas as pd \n", | ||
64 | + "\n", | ||
65 | + "url = 'https://map.kakao.com/'\n", | ||
66 | + "driver = webdriver.Chrome(\"C:\\\\Users\\\\chromedriver.exe\")\n", | ||
67 | + "driver.get(url)\n", | ||
68 | + "key_word = '영통역식당' \n", | ||
69 | + "\n", | ||
70 | + "def time_wait(num, code):\n", | ||
71 | + " try:\n", | ||
72 | + " wait = WebDriverWait(driver, num).until(\n", | ||
73 | + " EC.presence_of_element_located((By.ID, code)))\n", | ||
74 | + " except:\n", | ||
75 | + " print(code, '태그를 찾지 못하였습니다.')\n", | ||
76 | + " driver.quit()\n", | ||
77 | + " return wait\n", | ||
78 | + "\n", | ||
79 | + "time_wait(10,'search.keyword.query')\n", | ||
80 | + "search = driver.find_element(By.ID, 'search.keyword.query')\n", | ||
81 | + "search.send_keys(key_word) # 검색어 입력\n", | ||
82 | + "search.send_keys(Keys.ENTER) # 엔터버튼 누르기\n", | ||
83 | + "\n", | ||
84 | + "res = driver.page_source # 페이지 소스 가져오기\n", | ||
85 | + "soup = BeautifulSoup(res, 'html.parser') # html 파싱하여 가져온다\n", | ||
86 | + "\n", | ||
87 | + "#info\\.search\\.place\\.list > li:nth-child(1) > div.head_item.clickArea > strong > a.link_name\n", | ||
88 | + "\n", | ||
89 | + "\n", | ||
90 | + "element_list = driver.find_elements(By.CLASS_NAME ,'link_name')\n", | ||
91 | + "store_list = []\n", | ||
92 | + "for i in range(len(element_list)):\n", | ||
93 | + " store_list.append(element_list[i].text)\n", | ||
94 | + "print(store_list)" | ||
95 | + ] | ||
96 | + } | ||
97 | + ], | ||
98 | + "metadata": { | ||
99 | + "kernelspec": { | ||
100 | + "display_name": "Python 3 (ipykernel)", | ||
101 | + "language": "python", | ||
102 | + "name": "python3" | ||
103 | + }, | ||
104 | + "language_info": { | ||
105 | + "codemirror_mode": { | ||
106 | + "name": "ipython", | ||
107 | + "version": 3 | ||
108 | + }, | ||
109 | + "file_extension": ".py", | ||
110 | + "mimetype": "text/x-python", | ||
111 | + "name": "python", | ||
112 | + "nbconvert_exporter": "python", | ||
113 | + "pygments_lexer": "ipython3", | ||
114 | + "version": "3.9.7" | ||
115 | + } | ||
116 | + }, | ||
117 | + "nbformat": 4, | ||
118 | + "nbformat_minor": 5 | ||
119 | +} |
-
Please register or login to post a comment