
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
안녕하세요
app.py 코드에 대한 설명을 달았는데 검토해 주시고, 수정, 보충해주시면 감사하겠습니다.
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
#플라스크서버 만들거야
from pymongo import MongoClient
client = MongoClient('mongodb+srv://sparta:test@cluster0.03ijx8m.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
# 몽고디비를 쓸거야
import requests
from bs4 import BeautifulSoup
#비에스포, 뷰티플숲으로 fetch하고, 크롤링할거야
@app.route('/')
def home():
return render_template('index.html')
#index.html주는 api절
@app.route("/movie", methods=["POST"])
def movie_post():
#포스트방식으로 연결할거야
url_receive = request.form['url_give']
comment_receive = request.form['comment_give']
유알엘, 코멘트 -기브 찾아서 리시브할거야
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(url_receive,headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
리시브한 유알엘로부터 리퀘스츠와 뷰티풀숲으로 요소를 추출할거야
ogtitle = soup.select_one('meta[property="og:title"]') ['content']
ogimage = soup.select_one('meta[property="og:image"]') ['content']
ogdesc = soup.select_one('meta[property="og:description"]') ['content']
입력 유알엘이 소유한 제목,이미지,영화설명을 스크롤할거야
doc = {'title':ogtitle,
'desc':ogdesc,
'image':ogimage,
'comment':comment_receive
}
db.movies.insert_one(doc)
#데이터베이스 문서 필드에 제목,디스,이미지,코멘트를 달아서
#몽고 콜렉션 무비스에 저장할거야
return jsonify({'msg':'POST 저장완료!'})
@app.route("/movie", methods=["GET"])
def movie_get():
return jsonify({'msg':'GET 연결 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
