1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import csv
- from youtubesearchpython import *
- from tqdm import tqdm
- import time
- pages = 50
- max_channels = 8 * pages
- search = ChannelsSearch('微電影', limit = 8)
- c_list = []
- print('Filtering Channels................')
- for p in tqdm(range(pages)):
- for channel in search.result()['result']:
-
- if channel['subscribers'] is None:
- continue
- subscribes = channel['subscribers'].replace(' subscribers','').replace(' subscriber','')
-
- if 'K' in subscribes:
- subscribes = subscribes.replace('K','')
- if '.' in subscribes :
- subscribes=subscribes.replace('.','')
- subscribes+='00'
- else:
- subscribes+='000'
- if 'M' in subscribes:
- subscribes = subscribes.replace('M','')
- if '.' in subscribes :
- zeros = len(subscribes)-subscribes.index('.')-1
- subscribes=subscribes.replace('.','')
- subscribes += '000000'[:6-zeros]
- if int(subscribes)>100:
- c_list.append(channel)
- search.next()
-
- print('There is ',len(c_list),' channels')
- v_list = []
- for ch in c_list:
- channel_id = ch['id']
- try:
- search = ChannelSearch('*', channel_id)
- result = search.result()['result']
- for r in result:
- print(r.keys())
- print(r['channel']['name'])
- except:
- print(channel_id)
- '''
- with open('youtubeReport.csv', 'w', newline='') as csvfile:
- writer = csv.writer(csvfile)
- writer.writerow(['channel', 'title', '體重'])
- writer.writerow(['令狐沖', 175, 60])
- for r in results:
- print(r.keys())
- print(r['title'])
- '''
|