簡體   English   中英

解析表與美麗的湯

[英]Parsing Table With Beautiful Soup

我正在編寫一個程序,該程序可以轉到我的學校成績站點,並獲取我的成績並使它們成為我的桌面背景,但是一旦達到我的成績,我就無法從大型表格中解析它們

這是我的代碼:

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
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)
html = driver.page_source
soup = BeautifulSoup(html)
print soup
driver.quit()

print "done"

這將打印頁面的源,但是我想從稱為S2的行中獲取成績,對不起,這有點難,因為我無法向您顯示實際的網站

這是表中所有行的名稱:

<table class="grid">
<tr><th class="center" colspan="25">Attendance By Class</th></tr>
<tr class="center th2">
<th rowspan="2">Exp</th>
<th colspan="5">Last Week</th><th colspan="5">This Week</th><th rowspan="2">Course</th>
<th rowspan="2">Q1</th>
<th rowspan="2">Q2</th>
<th rowspan="2">S1</th>
<th rowspan="2">Q3</th>
<th rowspan="2">Q4</th>
<th rowspan="2">S2</th>
<th rowspan="2">Absences</th>
<th rowspan="2">Tardies</th>
</tr>

這是一個示例行:

<a href="scores.html?  frn=004711281&begdate=01/23/2013&enddate=06/07/2013&fg=S2">B<br>84</a></td>
<td><a

該資源可能會幫助您: 在硒中定位元素

您可以嘗試使用

find_element_by_link_text

以及其中一門課程的名稱,以獲得包含該課程成績的元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM