
영화 평점 데이터 print해서는 문제 없이 나오는데
doc로 정리해서 데이터베이스에만 넣을려고하면 에러가 뜨네요 ㅠㅠ
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
client = MongoClient('mongodb+srv://sparta2:test@cluster0.3zoajga.mongodb.net/Cluster0?retryWrites=true&w=majority')
db = client.dbsparta
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('https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=pnt&date=20210829',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
movies = soup.select('#old_content > table > tbody > tr')
for movie in movies:
a = movie.select_one('td.title > div > a')
if a is not None:
title = a.text
rank = movie.select_one('td:nth-child(1) > img')['alt']
star = movie.select_one('td.point').text
doc = {
'title': title,
'rank': rank,
'star': star}
db.users.insert_one(doc)
C:\Users\leehyunsuk\Desktop\sparta\pythonpra\venv\Scripts\python.exe C:/Users/leehyunsuk/Desktop/sparta/pythonpra/hello.py
File "C:/Users/leehyunsuk/Desktop/sparta/pythonpra/hello.py", line 22
doc = {
^
IndentationError: unexpected indent
종료 코드 1(으)로 완료된 프로세스
이건 오류코드입니다!
뭐가 문제일까요..ㅠㅠ
