스마트스토어 댓글 크롤링 - eagle705/python-for-marketing-analytics Wiki


from selenium import webdriver
import time

chromedriver = 'chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
def get_review_lines(url, target_class_name, start=1, end=5):

    driver.get(url)
    time.sleep(4)

    lst_comment = []
    for i in range(start+1,end+1):
        next_page_button_css = "#REVIEW > div > div._2y6yIawL6t > div > div.cv6id6JEkg > div > div > a:nth-child({})".format(i)
        button = driver.find_element_by_css_selector(next_page_button_css)
        button.click()
        time.sleep(2)
        comments_obj = driver.find_elements_by_css_selector(target_class_name)

        lst_comment += [comment.text for comment in comments_obj]
    return lst_comment

lst_comment = get_review_lines(url="https://brand.naver.com/jnjofficial/products/5528616467", 
                               target_class_name="._19SE1Dnqkf ._3QDEeS6NLn",
                               start=1, end=5)