-
Notifications
You must be signed in to change notification settings - Fork 1
/
badge_scraper.py
92 lines (82 loc) · 2.67 KB
/
badge_scraper.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import pandas as pd
from selenium.webdriver.chrome.options import Options
def remove_tags(html):
soup = BeautifulSoup(html, "html.parser")
for data in soup(['style', 'script']):
data.decompose()
return ' '.join(soup.stripped_strings)
df = pd.read_csv('Participant_Details.csv')
df1 = df[['url', 'name','email']]
saved_column = df.url
paragraphs = ""
name=[]
badges=[]
email=[]
completed_all=[]
score=[]
kotlin_basics=[]
funct=[]
classes_objects=[]
build_app=[]
layouts=[]
app_navigation=[]
for v,w,z in zip(df1.url,df1.name,df1.email):
paragraphs=""
kotlin_basics_s = "No"
funct_s = "No"
classes_objects_s = "No"
build_app_s = "No"
layouts_s = "No"
app_navigation_s = "No"
completed_all_s = "No"
score_s = 0
options = Options()
options.headless = True
wd = webdriver.Chrome(options=options)
responce = wd.get(v)
name.append(w)
email.append(z)
time.sleep(8)
soup = BeautifulSoup(wd.page_source, 'lxml')
div = soup.find_all('div', {'class':'badge-title'})
badgelist=""
for x in div:
badgelist=remove_tags(str(x))+", "+badgelist
paragraphs=paragraphs+(str(x))
if "Lesson 1: Kotlin Basics" in paragraphs:
kotlin_basics_s="Yes"
score_s+=1
if "Lesson 2: Functions" in paragraphs:
funct_s="Yes"
score_s+=1
if "Lesson 3: Classes and Objects" in paragraphs:
classes_objects_s="Yes"
score_s+=1
if "Lesson 4: Build your first Android app" in paragraphs:
build_app_s="Yes"
score_s+=1
if "Lesson 5: Layouts" in paragraphs:
layouts_s="Yes"
score_s+=1
if "Lesson 6: App navigation" in paragraphs:
app_navigation_s="Yes"
score_s+=1
kotlin_basics.append(kotlin_basics_s)
funct.append(funct_s)
classes_objects.append(classes_objects_s)
build_app.append(build_app_s)
layouts.append(layouts_s)
app_navigation.append(app_navigation_s)
if score == 6:
completed_all_s="Yes"
score.append(score_s)
completed_all.append(completed_all_s)
paragraphs = paragraphs + "<br><br>"
badges.append(badgelist)
dict = {'Name': name,'Email':email, 'Badges': badges, 'Kotlin Basics':kotlin_basics, 'Functions':funct, 'Classes and Objects':classes_objects, 'Build your first Android app':build_app, 'Layouts':layouts, 'App navigation':app_navigation, 'Score Out of 6':score,'Completed All Badges':completed_all}
df = pd.DataFrame(dict)
df.to_csv('Participant_Completion.csv')
paragraphs=remove_tags(paragraphs)