Restaurant_name.ipynb
3.6 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
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f383cd9b",
"metadata": {},
"outputs": [],
"source": [
"pip install selenium"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "65b02eed",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: lxml in c:\\users\\user\\anaconda3\\lib\\site-packages (4.6.3)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install lxml\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "91a38f02",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\User\\AppData\\Local\\Temp/ipykernel_2044/2241818007.py:12: DeprecationWarning: executable_path has been deprecated, please pass in a Service object\n",
" driver = webdriver.Chrome(\"C:\\\\Users\\\\chromedriver.exe\")\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"['소담촌 수원영통점', '쏘삼돼지208 영통점', '깡우동', '수원의아침', '삿뽀로 영통점', '가보정 영통점', '예랑', '윤가곰탕', '이가네양꼬치 영통점', '아웃백스테이크하우스 수원영통점', '보영만두 영통직영점', '육풍 영통프라임점', '그로또 영통점', '포명천천', '태백한우실비']\n"
]
}
],
"source": [
"import requests \n",
"from bs4 import BeautifulSoup\n",
"from selenium import webdriver\n",
"from selenium.webdriver.common.keys import Keys\n",
"from selenium.webdriver.common.by import By\n",
"from selenium.webdriver.support.ui import WebDriverWait\n",
"from selenium.webdriver.support import expected_conditions as EC\n",
"from time import sleep\n",
"import pandas as pd \n",
"\n",
"url = 'https://map.kakao.com/'\n",
"driver = webdriver.Chrome(\"C:\\\\Users\\\\chromedriver.exe\")\n",
"driver.get(url)\n",
"key_word = '영통역식당' \n",
"\n",
"def time_wait(num, code):\n",
" try:\n",
" wait = WebDriverWait(driver, num).until(\n",
" EC.presence_of_element_located((By.ID, code)))\n",
" except:\n",
" print(code, '태그를 찾지 못하였습니다.')\n",
" driver.quit()\n",
" return wait\n",
"\n",
"time_wait(10,'search.keyword.query')\n",
"search = driver.find_element(By.ID, 'search.keyword.query')\n",
"search.send_keys(key_word) # 검색어 입력\n",
"search.send_keys(Keys.ENTER) # 엔터버튼 누르기\n",
"\n",
"res = driver.page_source # 페이지 소스 가져오기\n",
"soup = BeautifulSoup(res, 'html.parser') # html 파싱하여 가져온다\n",
"\n",
"#info\\.search\\.place\\.list > li:nth-child(1) > div.head_item.clickArea > strong > a.link_name\n",
"\n",
"\n",
"element_list = driver.find_elements(By.CLASS_NAME ,'link_name')\n",
"store_list = []\n",
"for i in range(len(element_list)):\n",
" store_list.append(element_list[i].text)\n",
"print(store_list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}