3주자 목표
1. 원하는 페이지를 크롤링 한다.
2. pymongo를 통해 mongoDB를 제어할 수 있다.
예를 들어 지니 뮤직 사이트에 랭크 순위를 긁어와보자



#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.title.ellipsis
위와 같이 아로하 노래에 대한 선택자가 복사된다.
이러한 방법으로 랭킹, 타이틀, 가수 까지 긁어와서 목록을 완성시켜보자
trs = soup.select("#body-content > div.newest-list > div > table > tbody > tr")
for tr in trs:
title_tag = tr.select_one('td.info > a.title.ellipsis')
if title_tag is not None:
rank = tr.select_one('td.number').text[:2].strip()
title = title_tag.text.strip()
singer = tr.select_one('td.info > a.artist.ellipsis').text
print(rank, title, singer)

1 from pymongo import MongoClient
2
3 client = MongoClient('localhost', 27017)
4 db = client.dbsparta
이제 간단한 CRUD 메서드를 통해 조작해보자
doc = {
'rank': rank,
'title': title,
'star': star
}
db.movies.insert_one(doc)

data = db.movies.find_one({'title': '나 홀로 집에'})
print(data)
print(data['star'])

db.movies.update_one({"title": "매트릭스"}, {"$set": {"star": 0}})

db.users.delete_one({'name':'bobby'})
users 테이블에서 name이 bobby인 컬럼을 제거한다.