3rd week of Web development course

yjjhsh27·2022년 5월 11일

Web development course

목록 보기

The goals

🤓Quick review of last week

1. Understand the basic python syntax

2. Crawling pages

3. Control mongoDB through pymongo

🤔Practice-scraping music website

Quick review of last week


        function listing() {
             type: "GET",
             url: "http://spartacodingclub.shop/web/api/movie",
             data: {},
             success: function(response) {
                 let rows = response['movies']
                 for (let i = 0; i < rows.length; i++) {
                     let title = rows[i]['title']
                     let desc = rows[i]['desc']
                     let image = rows[i]['image']
                     let star = rows[i]['star']
                     let comment = rows[i]['comment']

                     let star_image = '⭐'.repeat(star)
                     let temp_html = `
                     <div class="col">
                         <div class="card h-100">
                             <img src="${image}"
                                 class="card-img-top" alt="...">
                             <div class="card-body">
                                 <h5 class="card-title">${title}</h5>
                                 <p class="card-text">${desc}</p>
                                 <p class="mycomment">${comment}</p>

        function open_box() {
        function close_box() {

Since last week I have learned what API is and how to use it, this time used movie API to get movie data and used jQuery to show the only what I need among all the API data.

What is Python?

Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby, Scheme, or Java.
Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. There are interfaces to many system calls and libraries, as well as to various windowing systems. New built-in modules are easily written in C or C++ (or other languages, depending on the chosen implementation). Python is also usable as an extension language for applications written in other languages that need easy-to-use scripting or automation interfaces.

❗️Indentation is really important in Python!

Understand the basic syntax of Python

Python package

We need to use library which is already made by other people to crawl with Python. We call it as "Python package".
Just imagine a situation that your project leader wants to change a version of project you are working on, then do we need to start all over again on new version?
Nope! definitely not! so we need "Virtual Environment" which we usually call as "venv". It contains python packages.

Installed package 'request' to extract selected data from API.


Try Beautiful Soup!

Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work.

This is the basic usage of Beautiful Soup. We can pull data out simply and quickly. In this case, I used IMDB movie ranking page to scrape data.


In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage.
We use a database to find data conveniently!

Connected to Mongo DB and uploaded data (above picture)

And then tried to extract data like above picture.

We can also update data directly by writing code below,


also delete data with this code.


Try out with some quizzes

# Bring the rating of movie '가버나움(Capernaum)'
movie = db.movies.find_one({'title':'가버나움'})

# Bring a movie has the same rating with Capernaum
star = movie['star']
all_movies = list(db.movies.find({'star': star},{'_id': False}))
for m in all_movies:

# Change the rating of Capernaum

🤔Practice-scraping music website

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/genre?ditc=D&ymd=20220510&genrecode=M0200',headers=headers)

soup = BeautifulSoup(data.text, 'html.parser')

songs = soup.select('#body-content > div.newest-list > div > table > tbody > tr')

for song in songs:
    rank = song.select_one('td.number').text[0:2].strip()
    title = song.select_one('td.info > a.title.ellipsis').text.strip()
    artist = song.select_one('td.info > a.artist.ellipsis').text
    print(rank, title, artist)

And then if we run this code, the result is printed out like this:

🤓 It was interesting to gather information I want from website! Through this chapter I could understand how the server works a bit!

Have no fear of perfection—you'll never reach it.
-Salvador Dalí


No special aptitude, but persistent effort

0개의 댓글