-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_grab.py
66 lines (59 loc) · 2.47 KB
/
web_grab.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
# Generated by Selenium IDE
import pytest
import time
import json
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
class Web_grab():
def setup(self):
self.driver = webdriver.Chrome(executable_path ="./chromedriver_win32/chromedriver.exe")
self.vars = {}
def teardown(self):
self.driver.quit()
def web_open(self):
# Test name: test1
# Step # | name | target | value
# 1 | open | /index.php?c=qry_all |
self.driver.get("https://course.ncku.edu.tw/index.php?c=qry_all")
# 2 | click | xpath=//div[10]/div/div[2]/li[2] |
self.driver.find_element(By.XPATH, "//div[10]/div/div[2]/li[2]").click()
time.sleep(2)
#self.vars["class_name"] = self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(49) > td:nth-child(5)").text
#self.vars["availa"] = self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(49) > td:nth-child(8)").text
def web_detection(self):
self.vars["class_name"] = self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(49) > td:nth-child(5)").text
self.vars["avail"] = self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(49) > td:nth-child(8)").text
def lineNotifyMessage(token, msg):
headers = {
"Authorization": "Bearer " + token,
"Content-Type" : "application/x-www-form-urlencoded"
}
payload = {'message': msg}
r = requests.post("https://notify-api.line.me/api/notify", headers = headers, params = payload)
return r.status_code
if __name__== '__main__':
message = "\n is available now"
token =
func = Web_grab()
func.setup()
func.web_open()
#func.teardown()
#print(func.vars["avail"])
for i in range(5):
func.web_detection()
available = func.vars["avail"].split('/')
name = func.vars["class_name"].split(' ')[0]
if available[1]=="額滿":
lineNotifyMessage(token, "\n" + name + message + " ["+ str(i) + "].")
time.sleep(30)
func.teardown