[TIL]미니프로젝트_Day3

지냐킴·2022년 7월 17일
0

항해99 8기 TIL/WIL

목록 보기
3/41
post-thumbnail

22.07.13 수요일

🚀 TIL

  • 크롤링 했을때 태그 안의 text만 가져오기 위해 get_text()메소드를 사용한다
    (이거도 잘 먹히는 애들이 있어서 애먹었는데 결국 필요가 없...)
  • 크롤링 성공
    오디오를 크롤링하기 위해 에피소드 버튼 크롤링 후 클릭 그리고 오디오 재생으로 이어지기 위해 팀원들이 같이 도와줬다.
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)
  • API 중요 기획의 중요
    S.A 할 때 API를 대충 짰는지(사실 잘모르는거도 큼) 작업들이 어느정도 완성되고 코드들 합치면서 API가 계속 추가 되었다. 이래서 기획이 중요한가보다

💬

어제 밤새 git 사용법 검색해느라 늦게 잤더니 아주 죽을거같다. 끝이 보인다.
우리 팀원들은 참 능력자들이다 어쩜 저렇게 잘하지
착착 고쳐주시는데 나는 내일 썸네일이랑 화면 녹화를 하겠다고 지원해야겠다.
할 수 있는걸 하자!

profile
코린이일기

0개의 댓글

관련 채용 정보