python 크롤링 삽질2

in python •  6 years ago  (edited)

목표: 전과 동일

결과:1페이지 당 50행,  50페이지* 출력

원인 : for문 안에 있는 click

import requests
from bs4 import BeautifulSoup
import time
from selenium import webdriver
#from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome('C:\\Users\\kyooj\\Desktop\\chrome\\chromedriver')
driver.get('http://www.nsdi.go.kr/lxportal/?menuno=2776')

city = driver.find_element_by_id('shSido')
for option in city.find_elements_by_tag_name('option'):
    if option.text == ' 서울특별시':
        option.click()
driver.find_element_by_xpath(' // *[ @ id = "searchVO"] / div[1] / div / select / option[5]').click()
driver.find_element_by_xpath('//*[@id="icon_btn_write"]').click()
html = driver.page_source

soup = BeautifulSoup(html, 'html.parser')

a_list = []

for i in range(1, 51):
    path = '//*[@id="searchVO"]/div[2]/table/tbody/tr'
    num = i
    num= str(num)
    xpath = path+'['+num+']'
    table_list = driver.find_element_by_xpath(xpath).text
    test = table_list
    print(test)
    continue
    driver.find_element_by_xpath('//*[@id="searchVO"]/div[2]/div[2]/ol/li[12]/a').click()
print(type(test))


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!