๐Ÿ“’ [ TIL ] 2022.04.18_1์ผ์ฐจ # ๊ธฐ์ดˆ๊ฐ•์˜ํ•™์Šต(1)

๋ฌธ๋ช…์ฃผยท2022๋…„ 4์›” 18์ผ
1

[ 2022-04-18 (์›”) ์˜ค๋Š˜์˜ TIL ]

[ Today Learn ]

  • HTML, CSS ์ •์˜ ๋ฐ ์ ์šฉ์—ฐ์Šต
  • ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ด์šฉํ•˜๊ธฐ
  • ํฐํŠธ์™€ ์ฃผ์„๋‹ฌ๊ธฐ
  • javascript ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ
  • Ajax์™€ Jquery ์ ์šฉํ•˜๊ธฐ
  • requests ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ์›น์Šคํฌ๋ž˜ํ•‘ ๋ฐฐ์šฐ๊ธฐ
  • DB์— ์ €์žฅํ•˜๊ธฐ

โœ๏ธ 1๊ฐ• ๋ณต์Šต

1. HTML, CSS

HTML์€ ๋ผˆ๋Œ€, CSS๋Š” ๊พธ๋ฏธ๊ธฐ!
HTML์€ headํƒœ๊ทธ(ํŽ˜์ด์ง€์ •๋ณด ๋ฐ ํŽ˜์ด์ง€๋‚ด์šฉ)์™€ bodyํƒœ๊ทธ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ | HTML ๊ธฐ์ดˆ</title>
</head>

<body>
<!-- ๊ตฌ์—ญ์„ ๋‚˜๋ˆ„๋Š” ํƒœ๊ทธ๋“ค -->
<div>๋‚˜๋Š” ๊ตฌ์—ญ์„ ๋‚˜๋ˆ„์ฃ </div>
<p>๋‚˜๋Š” ๋ฌธ๋‹จ์ด์—์š”</p>
<ul>
<li> bullet point!1 </li>
<li> bullet point!2 </li>
</ul>

<!-- ๊ตฌ์—ญ ๋‚ด ์ฝ˜ํ…์ธ  ํƒœ๊ทธ๋“ค -->
<h1>h1์€ ์ œ๋ชฉ์„ ๋‚˜ํƒ€๋‚ด๋Š” ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค. ํŽ˜์ด์ง€๋งˆ๋‹ค ํ•˜๋‚˜์”ฉ ๊ผญ ์จ์ฃผ๋Š” ๊ฒŒ ์ข‹์•„์š”. ๊ทธ๋ž˜์•ผ ๊ตฌ๊ธ€ ๊ฒ€์ƒ‰์ด ์ž˜ ๋˜๊ฑฐ๋“ ์š”.</h1>
<h2>h2๋Š” ์†Œ์ œ๋ชฉ์ž…๋‹ˆ๋‹ค.</h2>
<h3>h3~h6๋„ ๊ฐ์ž์˜ ์—ญํ• ์ด ์žˆ์ฃ . ๋น„์ค‘์€ ์ž‘์ง€๋งŒ..</h3>
<hr>
span ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: ํŠน์ • <span style="color:red">๊ธ€์ž</span>๋ฅผ ๊พธ๋ฐ€ ๋•Œ ์จ์š”
<hr>
a ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <a href="http://naver.com/"> ํ•˜์ดํผ๋งํฌ </a>
<hr>
img ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" />
<hr>
input ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <input type="text" />
<hr>
button ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <button> ๋ฒ„ํŠผ์ž…๋‹ˆ๋‹ค</button>
<hr>
textarea ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <textarea>๋‚˜๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?</textarea>
</body>

</html>

2. HTML ๋ถ€๋ชจ-์ž์‹ ๊ตฌ์กฐ

๋นจ๊ฐ„์ƒ‰ div์•ˆ์—์„œ ์ดˆ๋ก์ƒ‰ div๋กœ ๋”ฐ๋กœ ๋ฌถ๊ฒŒ ๋˜๋ฉด ์ดˆ๋ก์ƒ‰ div๋Š” ๊ทธ์˜ ์†์„ฑ์„ ๋”ฐ๋ผ๊ฐ€๊ฒŒ๋œ๋‹ค.

3. CSS ์—ฐ์Šต

css๋Š” head ํƒœ๊ทธ์•ˆ์—์„œ style ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด ์ž‘์„ฑํ•œ๋‹ค.
class๋ฅผ ๊ฐ€๋ฆฌํ‚ฌ๋•Œ๋Š” .์„ ๋ถ™์—ฌ ์ž‘์„ฑ !!

4. ํฐํŠธ, ์ฃผ์„

์›นํฐํŠธ link ํƒœ๊ทธ๋ฅผ ๋ณต์‚ฌํ•ด headํƒœ๊ทธ ์•ˆ์— ๋„ฃ์–ด์ฃผ๊ณ , css์š”์†Œ๋ฅผ styleํƒœ๊ทธ์— ๋‹ฌ์•„์ค€๋‹ค.

5. ์ฃผ์„๋‹ฌ๊ธฐ(ctrl+/)

์ฃผ์„์€ ์ฝ”๋“œ๋ฅผ ์ž ์‹œ ์ด์šฉํ•˜์ง€์•Š์„๋•Œ๋‚˜, ์ฝ”๋“œ์— ๋ถ€๊ฐ€ ์„ค๋ช…์„ ์จ๋†“๊ณ  ์‹ถ์„๋•Œ ์ด์šฉํ•œ๋‹ค. (์ฃผ์„์€ ์ปดํ“จํƒ€๊ฐ€ ์ฝ์ง€ ์•Š์Œ)

6. ๋ถ€ํŠธ์ŠคํŠธ๋žฉ(bootstrap)

๋ถ€ํŠธ์ŠคํŠธ๋žฉ์ด๋ž€ ๋‚จ์ด ๋งŒ๋“ค์–ด ๋†“์€ css๊พธ๋Ÿฌ๋ฏธ๋ฅผ ๋งํ•˜๋ฉฐ, ์ด๋ฅผ ๊ฐ€์ ธ๋‹ค ์“ธ ์ˆ˜ ์žˆ๋‹ค.

7. Javascript ๊ธฐ์ดˆ

1) ๋ณ€์ˆ˜ 2) ํ•จ์ˆ˜ 3) ์ž๋ฃŒํ˜•(๋ฆฌ์ŠคํŠธ & ๋”•์…”๋„ˆ๋ฆฌ) 4) ์กฐ๊ฑด๋ฌธ 5) ๋ฐ˜๋ณต๋ฌธ


โœ๏ธ 2๊ฐ• ๋ณต์Šต

1. jQuery

jQuery๋ž€ HTML์š”์†Œ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” javascript๋ฅผ ๋ฏธ๋ฆฌ ์ž‘์„ฑํ•ด๋‘” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.
์ด๋ฏธ ์งœ์—ฌ์ง„ ์ฝ”๋“œ์ด๊ธฐ ๋•Œ๋ฌธ์— '์ž„ํฌํŠธ' ๋ฅผ ํ•ด์•ผํ•œ๋‹ค.
javascript๋ณด๋‹ค ๋งค์šฐ ์ง๊ด€์ ์ž„.
EX)

$('#url').val(); // id๊ฐ€ url์ธ input ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ.
$('#post-box').hide();  // id๊ฐ€ post-box์ธ ๊ณณ์„ ์ˆจ๊ธฐ๊ธฐ
$('#post-box').show(); //id๊ฐ€ post-box์ธ ๊ณณ์„ ๋ณด์ด๊ธฐ

2. Ajax

API( ๋Œ€ํ‘œ์ ์œผ๋กœ GET์š”์ฒญ, POST์š”์ฒญ์ด ์žˆ์Œ)๋Š” ์€ํ–‰์˜ ์ฐฝ๊ตฌ์™€ ๊ฐ™์Œ!
1) GET

https://movie.naver.com/movie/bi/mi/basic.nhn?code=161967
์œ„ ์ฃผ์†Œ์—์„œ ? ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์•ž๋ถ€๋ถ„์ด ์„œ๋ฒ„์ฃผ์†Œ, ๋’ท๋ถ€๋ถ„์ด ์˜ํ™”๋ฒˆํ˜ธ(ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„๊ฐ€ ์•ฝ์†ํ•œ ๊ฐ’)์ž„.

ajax๋กœ ๋ฏธ์„ธ๋จผ์ง€ JSONํ˜•ํƒœ(๋ฆฌ์ŠคํŠธ์™€ ๋”•์…”๋„ˆ๋ฆฌ๊ฐ€ ํ•ฉ์ณ์ง„ ๋ฐ์ดํ„ฐ) openAPI๋ฅผ ์ด์šฉํ•ด ๋ชจ๋“  ๊ตฌ์˜ ๋ฏธ์„ธ๋จผ์ง€ ๊ฐ’์„ ์ฝ˜์†”์ฐฝ์— ์ฐ์–ด๋ณด๊ธฐ

$.ajax({
  type: "GET",
  url: "http://spartacodingclub.shop/sparta_api/seoulair",
  data: {},
  success: function (response) {
    let mise_list = response["RealtimeCityAir"]["row"];
    for (let i = 0; i < mise_list.length; i++) {
      let mise = mise_list[i];
      let gu_name = mise["MSRSTE_NM"];
      let gu_mise = mise["IDEX_MVL"];
      console.log(gu_name, gu_mise);
    }
  }
});

โœ๏ธ 3๊ฐ• ๋ณต์Šต

1. requests ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•˜๊ธฐ

requests ์ž„ํฌํŠธ ํ•„์ˆ˜! ๋“ค์—ฌ์“ฐ๊ธฐ ์ค‘์š”!
์œ„์—์„œ ๋ณธ ๋ฏธ์„ธ๋จผ์ง€ openAPI๋ฅผ ์ด์šฉํ•ด ๋ชจ๋“  ๊ตฌ์˜ ๋ฏธ์„ธ๋จผ์ง€ ๊ฐ’์„ ์ฐ์–ด๋ณด๊ธฐ

import requests 

r = requests.get('http://spartacodingclub.shop/sparta_api/seoulair')
rjson = r.json()

gus = rjson['RealtimeCityAir']['row']

for gu in gus:
	print(gu['MSRSTE_NM'], gu['IDEX_MVL'])

2. ์›น์Šคํฌ๋ž˜ํ•‘ ํ•ด๋ณด๊ธฐ

์›น์Šคํฌ๋ž˜ํ•‘์„ ํ•˜๊ธฐ์œ„ํ•ด requests์™€ bs4๋ฅผ ์ž„ํฌํŠธํ•˜์—ฌ ๊ฒ€์ƒ‰ํ•˜๊ธฐ ์‰ฌ์šด ์ƒํƒœ๋กœ ๋งŒ๋“ค๊ณ , ๊ทธ ํ›„์— ์ฝ”๋”ฉ์„ ํ•ด์„œ ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ์ฐพ์•„๋‚ธ๋‹ค. (์„ ํƒ์ž ์‚ฌ์šฉ copy selector)

import requests
from bs4 import BeautifulSoup

# URL์„ ์ฝ์–ด์„œ HTML๋ฅผ ๋ฐ›์•„์˜ค๊ณ ,
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://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=pnt&date=20210829',headers=headers)

# HTML์„ BeautifulSoup์ด๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•ด ๊ฒ€์ƒ‰ํ•˜๊ธฐ ์šฉ์ดํ•œ ์ƒํƒœ๋กœ ๋งŒ๋“ ๋‹ค 
soup = BeautifulSoup(data.text, 'html.parser')

# select๋ฅผ ์ด์šฉํ•ด์„œ, tr๋“ค์„ ๋ถˆ๋Ÿฌ์˜ค๊ณ ,
movies = soup.select('#old_content > table > tbody > tr')

# for ๋ฌธ์„ ์ด์šฉํ•ด ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฆฌ๊ณ ,
for movie in movies:
    # movie ์•ˆ์— a ๊ฐ€ ์žˆ์œผ๋ฉด,
    a_tag = movie.select_one('td.title > div > a')
    if a_tag is not None:
        # a์˜ text๋ฅผ ์ฐ์–ด๋ณธ๋‹ค.
        print (a_tag.text)

3. DB์— ์ €์žฅํ•˜๊ธฐ

1) DB๋ฅผ ์“ฐ๋Š” ์ด์œ ๋Š”?
๋‚˜์ค‘์— ์ž˜ ๋ฝ‘์•„ ์“ฐ๊ธฐ ์œ„ํ•ด์„œ!
2) DB์˜ ์ข…๋ฅ˜ (SQL / NoSQL)
3) pymongo ์„ธํŒ…

from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.55vah.mongodb.net/Cluster0?retryWrites=true&w=majority')
db = client.dbsparta

4) ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์˜ˆ์‹œ

  • ์ €์žฅ
    db.users.insert_one(doc)
  • ํ•œ ๊ฐœ ์ฐพ๊ธฐ
    user = db.users.find_one({'name':'bobby'})
  • ์—ฌ๋Ÿฌ ๊ฐœ ์ฐพ๊ธฐ
    all_users = list(db.users.find({},{'_id':False}))
  • ๋ฐ”๊พธ๊ธฐ (์—…๋ฐ์ดํŠธ)
    db.users.update_one({'name':'bobby'},{'$set':{'age':19}})
  • ์ง€์šฐ๊ธฐ
    db.users.delete_one({'name':'bobby'})

๐ŸŒฑ ๋Š๋‚€ ์ 

๊ธฐ๋‹ค๋ฆฌ๊ณ  ๊ธฐ๋‹ค๋ฆฌ๋˜ ๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ 1์ฃผ์ฐจ๊ฐ€ ๋“œ๋””์–ด ์‹œ์ž‘์ด๋‹ค.
๋‚ด์ผ๋ฐฐ์›€์บ ํ”„๋ฅผ ์ง„ํ–‰ํ•˜๊ธฐ ํ•œ๋‹ฌ์ „๋ถ€ํ„ฐ ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ ๋‚ด์ผ๋ฐฐ์›€๋‹จ๊ณผ ์›น๊ฐœ๋ฐœ์ข…ํ•ฉ๋ฐ˜์„ ๋ชจ๋‘ ๋ณต์Šตํ•˜๊ณ  ๋˜ ๋ณต์Šตํ•˜์—ฌ ์นผ์„ ๊ฐˆ์•˜๋‹ค!
๋‹คํ–‰ํžˆ ํŒ€์›๋“ค์ด ๋„ˆ๋ฌด๋‚˜ ์ฐฉํ•˜๊ณ  ์žฌ๋ฐŒ๋‹คใ… ใ…  ๊ฒŒ๋”์— ๋ชจ์ธ ์šฐ๋ฆฌํŒ€์›๋“ค ๋„˜ ๊ท€์—ฌ์›Œ ใ… 
์ฒ˜์Œ ๋งˆ์ฃผํ•œ ํŒ€์›(4๋ช…)๋“ค๊ณผ ํ•จ๊ป˜ ์œผ์Œฐ์œผ์Œฐํ•ด์„œ ๊ทธ๋ž˜๋„ ํ˜ผ์ž ํ•˜๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” ๋œ ํž˜๋“ค์—ˆ๋˜ ๊ฒƒ๊ฐ™๋‹ค.
์˜ค๋Š˜ ๊ณต๋ถ€ํ–ˆ๋˜ ๋ถ€๋ถ„์€ ์ด๋ฏธ ๋งŽ์ด ๋ณต์Šตํ•˜๊ณ  ์˜จ ๋ถ€๋ถ„์ด์–ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๊ธฐ์— ์•ž์„œ ๋˜ ๋‹ค์‹œ ํ•œ๋ฒˆ ๋” ๋ณต์Šตํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์ด์—ˆ๋‹ค.
๋ฐ˜๋ณตํ•ด์„œ ๊ณต๋ถ€ํ–ˆ๋˜ ๋ถ€๋ถ„์ด์–ด์„œ ์˜ค๋Š˜์€ ํฐ ์–ด๋ ค์›€์—†์ด ๊ณต๋ถ€ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.
์•„์ง ํŒ€์›๋“ค๊ณผ ์–ด์ƒ‰ํ•˜๊ธดํ•˜์ง€๋งŒ ๊ณง ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๋” ์นœํ•ด์ง€๋ฉฐ ๊ณต๋ถ€ํ•  ์ˆ˜ ์žˆ์„๊ฒƒ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด๋“ ๋‹ค ~~!
๋‚ด์ผ์€ ๋˜ ์–ด๋–ค ์ด์•ผ๊ธฐ๋ฅผ ๋‚˜๋ˆŒ์ง€ ๊ธฐ๋Œ€๋œ๋‹น

profile
ํ•˜๋ฃจ ํ•œ๊ฑธ์Œ์”ฉ ๊พธ์ค€ํžˆ ๋‚˜์•„๊ฐ€๋Š” ๊ฐœ๋ฐœ์ž๐Ÿ™†โ€โ™€๏ธ https://github.com/Moonmooj

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2022๋…„ 4์›” 19์ผ

์ค€๋น„๋„ ์ž˜ํ•ด์˜ค์‹œ๊ณ  ์—ด์ •๋„ ๋„˜์น˜์‹œ๋Š”๊ตฌ์š”!! ์ €๋„ ๊ฐ™์ด ์œผ์Œฐ์œผ์Œฐ~

1๊ฐœ์˜ ๋‹ต๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด