无法将课程代码输入时间表,时间表返回空
Can not enter course code into timetable, timetable is returning empty
我正在为大学时间表创建一个新系统,我正在寻找时间表中的空闲时段(学生没有讲座)。我需要输入课程代码,因为目前它正在打开一个空白的时间表,所以我需要能够在(例如 CASE2)
中输入课程代码
这是我的代码
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window() #opens up website, probably not needed.
driver.implicitly_wait(30)
driver.get('https://opentimetable.dcu.ie/')
df2=pd.read_html(driver.find_element_by_id("week-pdf-content").get_attribute('outerHTML'))[0]
# currently not searching for anything.
print(df2)
代码必须表现得像真人。
所以你必须
- select 下拉菜单和
.click()
打开列表和下一个 select 选项 Programmes of study
,或者使用特殊的 class Select()
这个,
- select 字段
Search
和 .send_key("CASE2")
,
- select 下面列表中的复选框
[ ] CASE2
和 .click()
它。
已在 Firefox
和 Chrome
上测试 Linux。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import pandas as pd
import time
driver = webdriver.Chrome()
#driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('https://opentimetable.dcu.ie/')
select = Select(driver.find_element_by_tag_name("select"))
select.select_by_visible_text('Programmes of Study')
search = driver.find_element_by_id("textSearch")
search.send_keys("CASE2")
#checkbox = driver.find_element_by_xpath('.//input[@type="checkbox"]') # can find wrong `checkbox` - it would need `time.sleep` until it removes other `checkboxes`
checkbox = driver.find_element_by_xpath('.//input[following-sibling::div[contains(text(), "CASE2")]]') # it works but it is harder to remeber
#checkbox = driver.find_element_by_xpath('.//div[contains(text(), "CASE2")]') # it works (in this HTML) and it is simpler to remeber
checkbox.click()
time.sleep(3) # JavaScript needs time to replace data in table
html = driver.find_element_by_id("week-pdf-content").get_attribute('outerHTML')
df2 = pd.read_html(html)[0]
print(df2.to_string()) # to_string() to display all columns without `...`
我正在为大学时间表创建一个新系统,我正在寻找时间表中的空闲时段(学生没有讲座)。我需要输入课程代码,因为目前它正在打开一个空白的时间表,所以我需要能够在(例如 CASE2)
中输入课程代码这是我的代码
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window() #opens up website, probably not needed.
driver.implicitly_wait(30)
driver.get('https://opentimetable.dcu.ie/')
df2=pd.read_html(driver.find_element_by_id("week-pdf-content").get_attribute('outerHTML'))[0]
# currently not searching for anything.
print(df2)
代码必须表现得像真人。
所以你必须
- select 下拉菜单和
.click()
打开列表和下一个 select 选项Programmes of study
,或者使用特殊的 classSelect()
这个, - select 字段
Search
和.send_key("CASE2")
, - select 下面列表中的复选框
[ ] CASE2
和.click()
它。
已在 Firefox
和 Chrome
上测试 Linux。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import pandas as pd
import time
driver = webdriver.Chrome()
#driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('https://opentimetable.dcu.ie/')
select = Select(driver.find_element_by_tag_name("select"))
select.select_by_visible_text('Programmes of Study')
search = driver.find_element_by_id("textSearch")
search.send_keys("CASE2")
#checkbox = driver.find_element_by_xpath('.//input[@type="checkbox"]') # can find wrong `checkbox` - it would need `time.sleep` until it removes other `checkboxes`
checkbox = driver.find_element_by_xpath('.//input[following-sibling::div[contains(text(), "CASE2")]]') # it works but it is harder to remeber
#checkbox = driver.find_element_by_xpath('.//div[contains(text(), "CASE2")]') # it works (in this HTML) and it is simpler to remeber
checkbox.click()
time.sleep(3) # JavaScript needs time to replace data in table
html = driver.find_element_by_id("week-pdf-content").get_attribute('outerHTML')
df2 = pd.read_html(html)[0]
print(df2.to_string()) # to_string() to display all columns without `...`