Notice
Recent Posts
Recent Comments
Link
Dev.끄적끈적
항해99 week3 본문
import requests
from bs4 import BeautifulSoup
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://www.genie.co.kr/chart/top200?ditc=M&rtm=N&ymd=20210701',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.number
#body-content > div.newest-list > div > table > tbody > tr:nth-child(2) > td.number
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.title.ellipsis
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.artist.ellipsis
music = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for i in music:
rank = i.select_one('td.number').text[0:2].strip()
title = i.select_one('td.info > a.title.ellipsis').text.strip()
artist = i.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://test:sparta@cluster0.6hcta.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta
# 저장 - 예시
doc = {'name':'bobby','age':21}
db.users.insert_one(doc)
# 한 개 찾기 - 예시
user = db.users.find_one({'name':'bobby'})
# 여러개 찾기 - 예시 ( _id 값은 제외하고 출력)
all_users = list(db.users.find({},{'_id':False}))
# 바꾸기 - 예시
db.users.update_one({'name':'bobby'},{'$set':{'age':19}})
# 지우기 - 예시
db.users.delete_one({'name':'bobby'})
'항해99 사전강의 (html, css, js)' 카테고리의 다른 글
스파르타 웹개발 종합반 Notion 링크 (0) | 2022.03.23 |
---|---|
항해99 week 2 (0) | 2022.03.01 |
항해99 week1 (0) | 2022.03.01 |