상세 컨텐츠

본문 제목

웹개발 파이썬

코딩/웹개발

by joing_in 2023. 3. 21. 18:16

본문

let star_image = ''.repeat(star) => star_image에 을 star번 입력 

 

파이썬

 def sum(a,b,c):
    return a+b+c

 result = sum(1,2,3)

 print(result)
 
 =6이라고 출력

 

 ages =[5,10,13,23,25,9]

 for a in ages:
    if a>20:
        print('성인')
    else:
        print('청소년')

=> {}쓰면 순서대로 출력 안됨! 주의

ages에 하나하나를 a에 넣고 그 a를 밑에 가져다가 쓰자

 

import requests

rjson = r.json()

rows = rjson['RealtimeCityAir']['row']

for a in rows:
    gu_name = a['MSRSTE_NM']
    gu_mise = a['IDEX_MVL']
    print(gu_name, gu_mise)

 

a = soup.select_one('')

=>a를 솎아낸다(한개 일때)

 

 if a is not None:
if a != None:

a가 None과 같지 않다

 if a is None
 if a == None:

a가 None과 같다

 

퀴즈

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'}

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

trs = soup.select('#old_content > table > tbody > tr')
for tr in trs:
    a=tr.select_one('td.title > div > a')
    if a is not None:
        title=a.text
        rank=tr.select_one('td:nth-child(1) > img')['alt']
        star=tr.select_one('td.point').text
        print(rank, title, star)

속성은 .text가 아니라 ['alt']이다

'코딩 > 웹개발' 카테고리의 다른 글

웹개발 Flask  (0) 2023.03.21
웹개발 DB  (0) 2023.03.21
웹개발 Fetch  (2) 2023.03.21
웹개발 Javascript, JQuery 연습  (0) 2023.03.21
웹개발 Javascript  (0) 2023.03.21

관련글 더보기