최근 데이터베이스는 프로그램같은 것이다. 하지만 이마저도 요즘은 클라우드 형태로 제공한다.
라이브러리 설치가 필요하다.
pymongo, dnspython 패키지를 설치하자.
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')
trs = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for tr in trs:
title = tr.select_one('td.info > a.title.ellipsis').text.strip()
rank = tr.select_one('td.number').text[0:2].strip()
artist = tr.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)
for문을 사용하는 것에 좀 더 익숙해질 필요가 있는것 같다.
자료를 타고 타고 들어가는 것에 주의해서 공부해보자,
파이썬 기반의 웹프레임워크이다.
function save_comment() {
let name = $('#name').val()
let comment = $('#comment').val()
$.ajax({
type: "POST",
url: "/homework",
data: {'name_give':name, 'comment_give':comment},
success: function (response) {
alert(response["msg"])
window.location.reload()
}
});
}
클라이언트에서 자료 넣는 부분 체크하여 변수 지정해주기
data에서 지정한 변수(name,comment)를 어떤 데이터로 보낼지 지정(neme_give, comment_give)
성공하면 결과값 알람으로 띄우는 것으로 설정.
@app.route("/homework", methods=["POST"])
def homework_post():
name_receive = request.form["name_give"]
comment_receive = request.form["comment_give"]
doc = {
'name': name_receive,
'comment': comment_receive
}
db.homework.insert_one(doc)
return jsonify({'msg':'응원 완료!'})
@app.route("/homework", methods=["GET"])
def homework_get():
comment_list = list(db.homework.find({},{'_id':False}))
return jsonify({'comments':comment_list})
function show_comment() {
$('#comment-list').empty()
$.ajax({
type: "GET",
url: "/homework",
data: {},
success: function (response) {
let rows = response['comments']
for (let i = 0; i < rows.length; i++) {
let name = rows[i]['name']
let comment = rows[i]['comment']
let temp_html = `<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>${comment}</p>
<footer class="blockquote-footer">${name}</footer>
</blockquote>
</div>
</div>`
$('#comment-list').append(temp_html)
}
}
});
}
맥 적응하고 있는 나에게 certifi의 존재를 알려주신 구세주!
진짜 이거 없었으면 뭐가 문제지...?! 내가 문제인가?! 라면서 좌절 했을것 같다. 이 영광을 ys님에게 돌립니다!!!