-
Notifications
You must be signed in to change notification settings - Fork 1
/
utube.py
43 lines (40 loc) · 1.21 KB
/
utube.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import urllib.request
import urllib.parse
import json
from pprint import pprint
import string
from duckduckgo import search
import json
import time
YEAR = 2000
with open('data.json', encoding='cp1252') as fb_list:
fb = json.load(fb_list)
headers = {}
headers['Accept'] = \
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
headers['Accept-Encoding'] = 'gzip, defalte'
headers['Connection'] = 'keep-alive'
headers['User-Agent'] = \
'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0'
temp = [];
for x in range(0, len(fb)):
try:
t = json.loads(fb[x]);
if t['youtube'] != "":
name = t['name']
with urllib.request.urlopen(t['youtube']) as conn:
rr=conn.read()
soupp = BeautifulSoup(rr,'html.parser')
souppp = soupp.select(".watch-view-count")
data = {}
data["name"] = name
data["views"] = souppp[0].text.split(" ")[0]
pprint(data)
temp.append(json.dumps(data))
except:
print ('error occured')
with open('utube.json', 'w') as outfile:
json.dump(temp,outfile)