커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
1-5 업무자동화 엑셀다루기 코드 실행이 안됩니다.
undefined주차
북마크
이*학
댓글
3
추천
1
조회수
13
조회수
13
답변 완료

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

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


안녕하세요

1-5 업무자동화 엑셀다루기  따라하는데 코드 실행이 안됩니다.

어디서 뭐가 틀렸는지 모르겠어요 ㅠ


스파르타 즉문즉답스파르타 즉문즉답




!pip install bs4 requests

-------------------------------------------------

import requests

from bs4 import BeautifulSoup


from openpyxl import Workbook



def get_news(keyword):


  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)


  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']]

    sheet.append(row)


  wb.save(f"{keyword}.xlsx")

  wb.close()

---------------------------------------------------

get_news('삼성전자')

------------------------------------------------

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-82724b372f00> in <module>
----> 1 get_news('삼성전자')


1 frames

<ipython-input-12-80c861dd4812> in get_news(keyword)
     20     a = li.select_one('a.news_tit')
     21     rows = [a.text, a['href']]
---> 22     sheet.append(row)
     23 
     24   wb.save("{keyword}.xlsx")

/usr/local/lib/python3.8/dist-packages/openpyxl/worksheet/worksheet.py in append(self, iterable)
    658                     cell = content
    659                     if cell.parent and cell.parent != self:
--> 660                         raise ValueError("Cells cannot be copied from other worksheets")
    661                     cell.parent = self
    662                     cell.column = col_idx

ValueError: Cells cannot be copied from other worksheets


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