wldnjsl2001@khu.ac.kr

Add kakaomap Restaurant_name.ipynb

{
"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
}