Created
March 8, 2023 05:55
-
-
Save youtube-jocoding/f1eb661c040237b6b557d298bc169e9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
import time | |
options = webdriver.ChromeOptions() | |
options.add_experimental_option("excludeSwitches", ["enable-logging"]) | |
driver = webdriver.Chrome("C:/kefico/chromedriver.exe", options=options) | |
url = "https://mediahub.seoul.go.kr/news/issue/hotNewsList.do" | |
driver.get(url) | |
time.sleep(2) | |
news_List = driver.find_element(By.CSS_SELECTOR, "#news_List") | |
titleTags = news_List.find_elements(By.CSS_SELECTOR, ".tit") | |
summaryTags = news_List.find_elements(By.CSS_SELECTOR, ".summary") | |
linkTags = news_List.find_elements(By.CSS_SELECTOR, ".goArticleDetail") | |
titles = [] | |
summarys = [] | |
links = [] | |
for tag in titleTags: | |
title = tag.get_attribute("innerHTML") | |
title = title.replace("\n","").strip() | |
titles.append(title) | |
for tag in summaryTags: | |
summary = tag.get_attribute("innerHTML") | |
summary = summary.replace("<!-- max 3줄 -->","").replace(" "," ").strip() | |
summarys.append(summary) | |
for tag in linkTags: | |
js = tag.get_attribute("onclick") | |
link = "https://mediahub.seoul.go.kr/archives/"+js.split("'")[1] | |
links.append(link) | |
f = open("seoulNews.txt", 'w', encoding="utf-8") | |
for i in range(0,len(titles)): | |
data = f"제목: {titles[i]}\n요약:{summarys[i]}\n링크:{links[i]}\n\n" | |
f.write(data) | |
f.close() | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment