Spaces:
Runtime error
Runtime error
Commit
·
c885038
1
Parent(s):
a60b731
Update app.py
Browse files
app.py
CHANGED
@@ -4,21 +4,21 @@ import requests
|
|
4 |
|
5 |
|
6 |
def greet(link):
|
7 |
-
HEADER = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
|
8 |
#link = "https://youtu.be/vQUCSHUlN-k?si=FfIsODGjJDzIHOAS"
|
9 |
response = requests.get(link) #, headers=HEADER)
|
10 |
soup = BeautifulSoup(response.text, "html.parser")
|
11 |
#print (soup.prettify())
|
12 |
|
13 |
-
titleSoupMeta = soup.find("meta", property="og:title")
|
14 |
-
videoTitle = titleSoupMeta["content"] if titleSoupMeta else "NotFound"
|
15 |
-
result = {}
|
16 |
-
result["views"] = soup.find("meta", itemprop="interactionCount")['content']
|
17 |
|
18 |
#soup=soup.prettify()
|
19 |
#viewSoupMeta = [line for line in soup.split('viewCount') if "views" in line]
|
20 |
|
21 |
-
|
22 |
# Store JSON data in API_Data
|
23 |
#for key in API_Data:{
|
24 |
# print(key,":", API_Data[key])
|
@@ -33,7 +33,7 @@ def greet(link):
|
|
33 |
'''
|
34 |
#viewSoupMeta = API_Data #str(response).find("viewCount")
|
35 |
|
36 |
-
return
|
37 |
|
38 |
|
39 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
|
|
4 |
|
5 |
|
6 |
def greet(link):
|
7 |
+
#HEADER = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
|
8 |
#link = "https://youtu.be/vQUCSHUlN-k?si=FfIsODGjJDzIHOAS"
|
9 |
response = requests.get(link) #, headers=HEADER)
|
10 |
soup = BeautifulSoup(response.text, "html.parser")
|
11 |
#print (soup.prettify())
|
12 |
|
13 |
+
#titleSoupMeta = soup.find("meta", property="og:title")
|
14 |
+
#videoTitle = titleSoupMeta["content"] if titleSoupMeta else "NotFound"
|
15 |
+
#result = {}
|
16 |
+
#result["views"] = soup.find("meta", itemprop="interactionCount")['content']
|
17 |
|
18 |
#soup=soup.prettify()
|
19 |
#viewSoupMeta = [line for line in soup.split('viewCount') if "views" in line]
|
20 |
|
21 |
+
bcsresult=response.text[response.text.find("viewCount"):].split('"')[2]
|
22 |
# Store JSON data in API_Data
|
23 |
#for key in API_Data:{
|
24 |
# print(key,":", API_Data[key])
|
|
|
33 |
'''
|
34 |
#viewSoupMeta = API_Data #str(response).find("viewCount")
|
35 |
|
36 |
+
return bcsresult #soup.prettify()
|
37 |
|
38 |
|
39 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|