-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfree-courses.py
executable file
·75 lines (57 loc) · 1.74 KB
/
free-courses.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from bs4 import BeautifulSoup
import requests
from googlesearch import search
from datetime import date
import json
from os import system
from termcolor import colored
courses_last = {"source": "geeksgod", "courses": []}
def coupon_scraper(url):
content = requests.get(url).text
soup = BeautifulSoup(content, 'lxml')
coupon = soup.find('p', class_ = 'elementor-heading-title elementor-size-default').text
return coupon
def udemy_link(title):
query = title+' udemy course'
for j in search(query, tld="com", num=1, stop=1, pause=1):
return j
urls = ['https://geeksgod.com/category/freecoupons/udemy-courses-free/']
#banner
system('figlet -f slant Freedemy | lolcat')
print(colored('- BY GOKUL -'.center(50),'green'))
system("echo '\033[0;37m'")
print('='*110)
print('\n\n')
for i in urls:
content = requests.get(i).text
soup = BeautifulSoup(content, 'lxml')
courses = soup.find_all('div', class_ = 'item-details')
for course in courses:
course_json = dict()
try:
coupon = coupon_scraper(course.a["href"])
if coupon == None:
continue
title = course.h3.text
dat = course.time.text
udemylink = udemy_link(title)
print(f'Course Title : {title}')
print(f"Link : {udemylink}")
print(f'Date : {dat}')
print(f'coupon : {coupon}')
print(f'Enroll_link : {udemylink}?couponCode={coupon}')
print('\n')
print("="*110)
print('\n')
course_json['title'] = title
course_json['link'] = udemylink
course_json['date'] = dat
course_json['coupon'] = coupon
course_json['enroll'] = f'{udemylink}?couponCode={coupon}'
courses_last['courses'].append(course_json)
except:
pass
final = json.dumps(courses_last, indent=4)
file = open('courses.json', 'w')
file.write(final)
file.close()