In [1]:
import requests
import json
import pandas as pd
In [2]:
df = pd.DataFrame(columns = ['영화', '내 별점(y)', '평균별점', '평가자수', '등급', '장르', '국가', '상영시간', '년도'])
for page_num in range(1, 23):
response = requests.get("https://watcha.net/v2/users/jXaIHl0ZtdYZ/movies.json?filter%5Bsorting%5D=time&page={page}".format(
page=page_num))
watcha_dict = json.loads(response.text)
watcha_list = watcha_dict.get('cards')
for i in range(24):
rating = watcha_list[i].get('items')[0].get('item').get('owner_action').get('rating') # y값 : 나의 rating
title = watcha_list[i].get('items')[0].get('item').get('title')
avg_rating = watcha_list[i].get('items')[0].get('item').get('watcha_rating')
eval_count = watcha_list[i].get('items')[0].get('item').get('eval_count')
film_rate = watcha_list[i].get('items')[0].get('item').get('filmrate')
genre = watcha_list[i].get('items')[0].get('item').get('main_genre')
nation = watcha_list[i].get('items')[0].get('item').get('nation')
running_time = watcha_list[i].get('items')[0].get('item').get('running_time')
year = watcha_list[i].get('items')[0].get('item').get('year')
df.loc[len(df)] = [title, rating, avg_rating, eval_count, film_rate, genre, nation, running_time, year]
In [3]:
df
Out[3]:
In [4]:
df1 = pd.DataFrame(columns = ['영화', '내 별점(y)', '평균별점', '평가자수', '등급', '장르', '국가', '상영시간', '년도'])
response = requests.get("https://watcha.net/v2/users/jXaIHl0ZtdYZ/movies.json?filter%5Bsorting%5D=time&page=23")
watcha_dict = json.loads(response.text)
watcha_list = watcha_dict.get('cards')
len(watcha_list)
for i in range(16):
rating = watcha_list[i].get('items')[0].get('item').get('owner_action').get('rating') # y값 : 나의 rating
title = watcha_list[i].get('items')[0].get('item').get('title')
avg_rating = watcha_list[i].get('items')[0].get('item').get('watcha_rating')
eval_count = watcha_list[i].get('items')[0].get('item').get('eval_count')
film_rate = watcha_list[i].get('items')[0].get('item').get('filmrate')
genre = watcha_list[i].get('items')[0].get('item').get('main_genre')
nation = watcha_list[i].get('items')[0].get('item').get('nation')
running_time = watcha_list[i].get('items')[0].get('item').get('running_time')
year = watcha_list[i].get('items')[0].get('item').get('year')
df1.loc[len(df1)] = [title, rating, avg_rating, eval_count, film_rate, genre, nation, running_time, year]
In [5]:
df1
Out[5]:
In [6]:
watcha_df = df.append(df1, ignore_index=True)
watcha_df.tail(10)
Out[6]:
In [18]:
path='C:/Users/JKEUN/ipython notebook/project_01_watcha/resource/'
watcha_df.to_csv(path+'1st_df.csv', index=False, encoding='utf8')
In [ ]: