-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutubeparser.py
33 lines (28 loc) · 885 Bytes
/
youtubeparser.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
from bs4 import BeautifulSoup
import requests
import aiohttp
import asyncio
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
async def parsePlaylist(url):
try:
page = await aiohttp.post(url, headers=headers)
page = await page.text()
#page = requests.get(url, headers=headers)
soup = BeautifulSoup(page, 'html.parser')
tags = soup.find_all("tr", class_="pl-video yt-uix-tile ")
links = []
for tag in tags:
links.append("https://www.youtube.com/watch?v=" + tag['data-video-id'])
if links != []:
return links
else:
return False
except:
return False
async def getTitle(url):
try:
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
return soup.title.string.replace(" - YouTube", "")
except:
return False