-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmselenium.py
36 lines (28 loc) · 1.19 KB
/
mselenium.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
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.uia.no/studieplaner/search#tab-to-topics')
for _ in range(2500):
browser.execute_script("window.scrollBy(0,10000)")
ecode = browser.find_elements_by_xpath("//div[@class='class-topic']/h3/a/span/span/span[@class='attribute-code']")
etitle = browser.find_elements_by_xpath("//div[@class='class-topic']/h3/a/span/span/span[@class='attribute-title']")
eloc = browser.find_elements_by_xpath("//div[@class='class-topic']/h3/a/span/span/span[@class='attribute-location']")
eFullCode = browser.find_elements_by_xpath("//div[@class='class-topic']/h3/a")
codes = {}
for x in range(len(ecode)):
tempFCode = eFullCode[x].get_attribute('href').split('?')[0]
tempFCodeFrom = tempFCode.index('topic')+6
temp = {tempFCode[tempFCodeFrom:]: {
'title': etitle[x].get_attribute('innerHTML'),
'location': eloc[x].get_attribute('innerHTML')[:-5],
'strippedCode': ecode[x].get_attribute('innerHTML')
}}
codes.update(temp)
for x in codes:
print x
f = open('coursecodes.txt', 'w')
f.truncate()
f.write(str(codes))
f.close()
browser.close()