인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

프로그램초님의 프로필 이미지
프로그램초

작성한 질문수

[신규 개정판] 이것이 진짜 크롤링이다 - 실전편 (인공지능 수익화)

네이버 게임 라운지 게시글 댓글 크롤링

작성

·

445

·

수정됨

0

크롤링 하다가 막혔는데 어떻게 해결할 수 있을까요??

 

URL : https://game.naver.com/lounge/Viking_Rise/board/detail/2583518

사용 코드

import requests
from bs4 import BeautifulSoup
import openpyxl

url = "https://game.naver.com/lounge/Viking_Rise/board/detail/2583518"

response = requests.get(url)
html = response.text

soup = BeautifulSoup(html, "html.parser")

comment_items = soup.select(".comment_item_text__1foPs")

workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.title = "Crawled Comments"

sheet.cell(row=1, column=1, value="Comment Text")
sheet.cell(row=1, column=2, value="Attributes")

for index, comment_content in enumerate(comment_items, start=2):
    comment_text = comment_content.get_text(strip=True)
    comment_attributes = str(comment_content.attrs)
    
    sheet.cell(row=index, column=1, value=comment_text)
    sheet.cell(row=index, column=2, value=comment_attributes)

workbook.save("crawled_comments.xlsx")
print("Comment attributes have been crawled and saved to crawled_comments.xlsx")

답변 1

0

스타트코딩님의 프로필 이미지
스타트코딩
지식공유자

반갑습니다. 스타트코딩입니다.

질문주신 페이지는 동적인 페이지입니다.

일반적인 requests + bs4로는 크롤링할 수 없고

셀레니움이나 네트워크 분석을 통한 크롤링 방법을 사용해야 합니다.

 

아래는 네트워크에서 원하는 정보가 있는 통신을 찾은 스샷입니다.

image

감사합니다. (_ _)

프로그램초님의 프로필 이미지
프로그램초

작성한 질문수

질문하기