커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
1주차 1-9 왜 파일명에 now/ 를 붙이면 에러가 날까요?
금융인을 위한 파이썬 업무자동화 v0
1주차
북마크
박*원
댓글
1
추천
0
조회수
6
조회수
6
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



now만 안붙이면 잘 나오는데 now만 붙이면 에러가 나네요.



스파르타 즉문즉답





작성한 코드 및 에러 메세지

import requests

from bs4 import BeautifulSoup


from openpyxl import Workbook


from datetime import datetime  # 날짜 가져오는 라이브러리 추가 설치


def get_news(keyword):  # get_news 라는 함수를 만들기

  wb= Workbook()

  sheet = wb.active

 

  headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}

  data = requests.get(f'https://search.naver.com/search.naver?where=news&ie=utf8&sm=nws_hty&query={keyword}',headers=headers)   # f스트링 방식


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


  lis = soup.select('#main_pack > section > div > div.group_news > ul > li')

  for li in lis:

    a = li.select_one('a.news_tit')

    row = [a.text, a['href']]  # 기사제목과 링크를 row라는 리스트로 만들어주고,

    sheet.append(row)  # sheet에 추가해줌


  today = datetime.today().strftime("%Y-%m-%d") # 날짜를 가져와서 today라는 변수에 저장


  wb.save(f"now/{today}_{keyword}.xlsx")   # 파일명에 today 변수 추가 + news라는 폴더에 쌓이도록

  wb.close()


FileNotFoundError                         Traceback (most recent call last)
<ipython-input-36-82724b372f00> in <cell line: 1>()
----> 1 get_news('삼성전자')


3 frames

/usr/lib/python3.10/zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1249             while True:
   1250                 try:
-> 1251                     self.fp = io.open(file, filemode)
   1252                 except OSError:
   1253                     if filemode in modeDict:

FileNotFoundError: [Errno 2] No such file or directory: 'now/2023-10-13_삼성전자.xlsx'


취소
 공유
취소
댓글 0
댓글 알림
나의얼굴