22.07.13 수요일
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
driver = webdriver.Chrome('./chromedriver')
url = 'https://www.podbbang.com/channels/12548/episodes/24396721'
driver.get(url)
sleep(3)
req = driver.page_source
driver.quit()
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route("/podcast", methods=["POST"])
def podcast_post():
url_receive = request.form['url_give']
comment_receive = request.form['comment_give']
url = 'https://www.podbbang.com/channels/12548/episodes/24396721'
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')
soup_1 = BeautifulSoup(req, 'html.parser')
image = soup.select_one('meta[property="og:image"]')['content']
title = soup.select_one('meta[property="og:title"]')['content']
description= soup.select_one('meta[property="og:description"]')['content']
date = soup_1.select_one('#__layout > section > section.app-container > section > section.content-wrapper > section.misc > span.published-at > b').text
playtime = soup_1.select_one('#__layout > section > section.app-container > section > section.content-wrapper > section.misc > span.duration > b').text
like = soup_1.select_one('#__layout > section > section.app-container > section > section.content-wrapper > section.misc > span.likes').text
like_new = re.sub(r"\s","".text)
audio_btn = driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section[1]/section/section[1]/section[3]/button')
audio_btn.click()
driver.implicitly_wait(3)
audio = driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section[2]/audio')
audio_href = audio.get_attribute('src')
doc = {
'comment':comment_receive,
'title':title,
'image':image,
'description':description,
'date':date,
'playtime':playtime,
'like_new':like,
}
db.podshare.insert_one(doc)
return jsonify({'msg':'등록 완료!'})
@app.route("/podcast", methods=["GET"])
def podcast_get():
podcast_list = list(db.podshare.find({}, {'_id': False}))
return jsonify({'all_podcast':podcast_list})
@app.route('/api/delete', methods=['POST'])
def deleteRow():
comment_receive = request.form['comment_give']
db.podshare.delete_one({'comment': comment_receive})
return jsonify({'msg': '삭제 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5001, debug=True)
어제 밤새 git 사용법 검색해느라 늦게 잤더니 아주 죽을거같다. 끝이 보인다.
우리 팀원들은 참 능력자들이다 어쩜 저렇게 잘하지
착착 고쳐주시는데 나는 내일 썸네일이랑 화면 녹화를 하겠다고 지원해야겠다.
할 수 있는걸 하자!