Exemple #1
0
    for article_links_element in article_links_elements:
        article_links_element.send_keys(Keys.CONTROL + "\n")
        # for windows, Keys.CONTROL
        # for mac OS, Keys.COMMAND
        time.sleep(1)
        goNewTap(driver)
        time.sleep(1)
        print(getNewsInfo(driver))
        driver.close()
        goFirstTap(driver)
        break


# 메인 코드 시작
if __name__ == "__main__":
    driver = webdriver.Chrome(filepath.getChromeDriverPath())
    driver.get(
        "https://news.naver.com/main/main.nhn?mode=LSD&mid=sec&sid1=100")

    while True:
        startNewsCrawling(driver)

        if goNextPage(driver):
            print("Go To Next Page")
        else:
            print("It was last page")
            break

    driver.close()
from selenium import webdriver
import pandas as pd
import filepath

path = filepath.getChromeDriverPath()
driver = webdriver.Chrome(path)
driver.get(
    "https://news.naver.com/main/read.nhn?mode=LSD&mid=shm&sid1=100&oid=014&aid=0004332161"
)

article_title_element = driver.find_element_by_id("articleTitle")
article_body_element = driver.find_element_by_id("articleBodyContents")
article_date_elements = driver.find_elements_by_class_name("t11")  # 리스트가 반환됨
(article_input_date_element,
 article_last_modified_date_element) = article_date_elements

dataframe = pd.DataFrame({
    "title": [article_title_element.text],
    "body": [article_body_element.text],
    "input_date": [article_input_date_element.text],
    "last_modified_date": [article_last_modified_date_element.text],
})

csv_save_path = filepath.getPath("../../csv/article_1.csv")
dataframe.to_csv(csv_save_path, mode="w", index=False)

driver.close()