mmyjh86

네이버 - 데이터랩 통계

Aug 30th, 2020 (edited)
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from selenium import webdriver
  2.  
  3. driver = webdriver.Chrome('C:/Users/jongh/Desktop/chromedriver.exe')
  4. driver.implicitly_wait(3)
  5.  
  6. url = "https://datalab.naver.com/shoppingInsight/sCategory.naver"
  7. driver.get(url)
  8.  
  9. # 디지털/가전
  10. selector = "#content > div.section_instie_area.space_top > div > div.section.insite_inquiry > div > div > div:nth-child(1) > div > div:nth-child(1) > span"
  11. element = driver.find_element_by_css_selector(selector)
  12. element.click()
  13.  
  14. selector = "#content > div.section_instie_area.space_top > div > div.section.insite_inquiry > div > div > div:nth-child(1) > div > div:nth-child(1) > ul > li:nth-child(4) > a"
  15. element = driver.find_element_by_css_selector(selector)
  16. element.click()
  17.  
  18. # 휴대폰
  19. selector = "#content > div.section_instie_area.space_top > div > div.section.insite_inquiry > div > div > div:nth-child(1) > div > div:nth-child(2)"
  20. element = driver.find_element_by_css_selector(selector)
  21. element.click()
  22.  
  23. selector = "#content > div.section_instie_area.space_top > div > div.section.insite_inquiry > div > div > div:nth-child(1) > div > div:nth-child(2) > ul > li:nth-child(1) > a"
  24. element = driver.find_element_by_css_selector(selector)
  25. element.click()
  26.  
  27. # 순위 가져오기
  28. sel = "#content > div.section_instie_area.space_top > div > div > div.section_insite_sub > div > div > div.rank_top1000_scroll > ul > li > a"
  29. result = driver.find_elements_by_css_selector(sel)
  30. for item in result:
  31.     print(item.text[2:].replace("\n", ""))
RAW Paste Data