我正在使用 selenium 来访问我的学校成绩,之后我希望能够从网站上获取我的成绩,但我不知道如何
这是我的登录代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.PhantomJS("C:\Python27\phantomjs-1.9.0-windows\phantomjs.exe")
driver.get("https://ps.rsd.edu/public/")
elem = driver.find_element_by_name("account")
elem.send_keys("Username")
elem2 = driver.find_element_by_name("pw")
elem2.send_keys("Password")
elem.send_keys(Keys.RETURN)
driver.quit()
print "done"
我认为最简单的方法是使用 Beautifulsoup,但我不确定
最佳答案
我将在这里回答这个问题,因为另一个问题是关于如何使用 Beautifulsoup 解析表格。
因此给定表 http://gist.github.com/C-Dubb/5522909
for cell in driver.find_elements_by_css_selector(".grid tr a[href$='fg=S2']"):
print cell.text
# if you want the number only, you need to strip the grades here
# also need to check if S2 cell is empty or not
关于python - 使用 Python 抓取网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390262/