In [ ]:
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import csv
hdr = {'User-Agent': 'Mozilla/5.0', 'referer': 'http://www.naver.com'}
path = "/Users/codemath/Desktop/company/jupyter_notebook/chromedriver"
urls = "http://61.73.100.30/kr/bbs/iframe/list.jsp?bbsid=1273209703694"
# csv
f = open('output.csv', 'w')
wr = csv.writer(f)
wr.writerow([u'#', u'상호'.encode('utf-8'),u'홈페이지'.encode('utf-8'),u'대표자'.encode('utf-8'),u'모바일'.encode('utf-8')])
# endcsv
driver = webdriver.Chrome(path)
driver.get(urls)
a_link = 3
for each in range(1,153):
if each != 152:
sections = range(1,11)
else:
sections = range(1,5)
for li in sections:
ids = driver.find_element_by_xpath('//*[@id="content"]/div[2]/table/tbody/tr['+str(li)+']/td[1]').text
title = driver.find_element_by_xpath('//*[@id="content"]/div[2]/table/tbody/tr['+str(li)+']/td[2]').text
webs = driver.find_element_by_xpath('//*[@id="content"]/div[2]/table/tbody/tr['+str(li)+']/td[3]').text
name = driver.find_element_by_xpath('//*[@id="content"]/div[2]/table/tbody/tr['+str(li)+']/td[4]').text
mobile = driver.find_element_by_xpath('//*[@id="content"]/div[2]/table/tbody/tr['+str(li)+']/td[5]').text
wr.writerow([ids.encode('utf-8'),title.encode('utf-8'),webs.encode('utf-8'),name.encode('utf-8'),mobile.encode('utf-8')])
if a_link == 13:
a_link = 4
else:
a_link += 1
on_html_bt = driver.find_element_by_xpath('//*[@id="content"]/div[3]/div/a[%s]' %(a_link))
on_html_bt.click()
print "-----fin-----"
f.close()