강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của hongjunhyeok
hongjunhyeok

câu hỏi đã được viết

Tạo thông báo mở vé xem phim bằng Python

Đang thu thập thông tin về các tựa phim IMAX được mở để đặt trước

만약 imax상영을 여러개 한다면 어떻게 구현을 해야되나요?

Viết

·

316

0

.

python

Câu trả lời 1

1

저도 궁금해서 한번 코드 작성해보았는데, 여러개도 알림이 가도록 구현이 가능하네요! 
참고로 저는 imax 상영 영화 말고, tempurCinema 상영 영화로 했다는 점 유의하시길 바랍니다.
각각의 영화 별로 나눠진 col-times 클래스의 div 태그 안쪽 내용으로 반복문을 돌리며, temputCinema 클래스인 span 태그가 있는지 조건문으로 확인하고,

있다면 해당 col-times 클래스의 div 태그에 걸쳐지는 모든 영역 중 strong 태그의 텍스트를 선택하여 메시지를 전송할 수 있습니다.

import
requests
import telegram
from bs4 import BeautifulSoup
from apscheduler.schedulers.blocking import BlockingScheduler

bot = telegram.Bot(token = '5087679237:AAHASP7XCcdj26RHW20HZFt56YTzndsaZe0')
url = 'http://www.cgv.co.kr/common/showtimes/iframeTheater.aspx?areacode=01&theatercode=P013&date=20220121&screencodes=&screenratingcode=09&regioncode=103'

def job_function():
html = requests.get(url)

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

parent = soup.select('div.col-times')

for i in parent:
tempurCinema = i.select_one('span.tempurCinema')
if(tempurCinema):
title = i.select_one('div.info-movie > a > strong').text.strip()
bot.sendMessage(chat_id=5062868275, text=title + " tempurCinema 예매가 열렸습니다.")
sched.pause()
#else:
#bot.sendMessage(chat_id=5062868275, text = "tempurCinema 예매가 열리지 않았습니다.")
#print('tempurCinema 예매가 열리지 않았습니다.')


sched = BlockingScheduler()
sched.add_job(job_function, 'interval', seconds=5)
sched.start()
hongjunhyeok님의 프로필 이미지
hongjunhyeok
Người đặt câu hỏi

헐 ㅠㅠㅠㅠ 제가 파이썬 꼬꼬마시절때 질문한 것을 최근에 다시 보니까 새롭네요!!ㅋㅋ 
친절히 답변해주셔서 감사합니다~

그러고 보니, 2020년에 올라온 질문이었네요ㅋㅋ  

좋은 하루 보내세요~!

Hình ảnh hồ sơ của hongjunhyeok
hongjunhyeok

câu hỏi đã được viết

Đặt câu hỏi