import requests
from bs4 import BeautifulSoup
url = 'https://movies.yahoo.com.tw/movie_thisweek.html'
response = requests.get(url=url)
FW4=open('cim4.html','wb')
soup = BeautifulSoup(response.text, 'lxml')
info_items = soup.find_all('div', 'release_info')
for item in info_items:
name = item.find('div', 'release_movie_name').a.text.strip()
english_name = item.find('div', 'en').a.text.strip()
release_time = item.find('div', 'release_movie_time').text.split(':')[-1].strip()
level = item.find('div', 'leveltext').span.text.strip()
s=name+'=='+english_name+'=='+release_time+'=='+level+'
\n'
b=bytes(s,encoding="cp950")
FW4.write(b)
FW4.close()
import csv
info_items = soup.find_all('div', 'release_info')
with open('newmovie.csv', 'w', encoding='utf-8', newline='') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['ChineseName', 'EnglishName', 'DT', 'expectation'])
for item in info_items:
name = item.find('div', 'release_movie_name').a.text.strip()
english_name = item.find('div', 'en').a.text.strip()
release_time = item.find('div', 'release_movie_time').text.split(':')[-1].strip()
level = item.find('div', 'leveltext').span.text.strip()
csv_writer.writerow([name, english_name, release_time, level])