-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre_procedure.py
More file actions
68 lines (58 loc) · 1.92 KB
/
Copy pathpre_procedure.py
File metadata and controls
68 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import bs4
import csv
class Watch:
videoTitle = ""
Channel = ""
date = ""
FILE_NAME = "watch-history.html"
DATA_PATH = "./Data/" + FILE_NAME
# 入力データ
soup = bs4.BeautifulSoup(open(DATA_PATH), 'html.parser')
print("ok")
div_inside0 = soup.find_all("div", class_="content-cell mdl-cell mdl-cell--6-col mdl-typography--body-1")
with open('./CSVs/output.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow(["video_title", "video_id", "channel_name", "channel_id", "watch_date"])
f.close()
for div_inside in div_inside0:
div_inside2 = div_inside.find_all("a")
print("ok")
csvlist = []
i = 0
isSkip = False
isNone = True
for a in div_inside2:
isNone = False
if a.text.find('https://www.youtube.com/watch?v=') == 0:
isSkip = True
break
sample_txt = a.text
csvlist.append(sample_txt)
if i == 0:
sample_id = a.get('href')
sample_id = sample_id.replace('https://www.youtube.com/watch?v=', "")
csvlist.append(sample_id)
i = i + 1
continue
if i == 1:
sample_id = a.get('href')
sample_id = sample_id.replace('https://www.youtube.com/channel/', "")
csvlist.append(sample_id)
i = i + 1
if i == 2:
time = div_inside.text
time = time.replace(csvlist[0], '')
time = time.replace(csvlist[2], '')
time = time.replace('Watched\xa0', '')
#time = time.replace('\xa0を視聴しました', '')
csvlist.append(time)
i = i + 1
if isSkip:
continue
if isNone:
continue
with open('./CSVs/output.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow(csvlist)
f.close()
#-----------------------------------------------------------------------------------------------------------------