
웹스크래핑 결과 저장하기 하고 있는데 다음과 같은 오류가 뜹니다.
제가 어떤 부분에서 잘못한거죠??
C:\Users\admin\Desktop\sparta\pythonprac\venv\Scripts\python.exe C:/Users/admin/Desktop/sparta/pythonprac/hello.py
Traceback (most recent call last):
File "C:\Users\admin\Desktop\sparta\pythonprac\hello.py", line 11, in <module>
soup = BeautifulSoup(data.text, 'html.parser')
NameError: name 'data' is not defined
종료 코드 1(으)로 완료된 프로세스
from bs4 import BeautifulSoup
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://test:sparta@cluster0.jofibop.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta
soup = BeautifulSoup(data.text, 'html.parser')
title = soup.select_one('#old_content > table > tbody > tr:nth-child(2) > td.title > div > a')
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.movies.insert_one(doc)
해당 코드입니다.
