简体   繁体   English

解析表与美丽的汤

[英]Parsing Table With Beautiful Soup

Im writing a program that goes to my school grades site and takes my grades and makes them my desktop background but once i get to my grades i cant get how to parse them out of the large table 我正在编写一个程序,该程序可以转到我的学校成绩站点,并获取我的成绩并使它们成为我的桌面背景,但是一旦达到我的成绩,我就无法从大型表格中解析它们

Here is my code: 这是我的代码:

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"

this prints the source for the page but i want to get the grades out of a row called S2 sorry its kinda hard because i cant show you the actual site 这将打印页面的源,但是我想从称为S2的行中获取成绩,对不起,这有点难,因为我无法向您显示实际的网站

here are all the names of the rows in the table: 这是表中所有行的名称:

<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>

and this is an example row: 这是一个示例行:

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

This resource might help you: locating elements in selenium 该资源可能会帮助您: 在硒中定位元素

you might try using 您可以尝试使用

find_element_by_link_text

and the name of one of your courses to obtain an element containing the grades for that course 以及其中一门课程的名称,以获得包含该课程成绩的元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM