【问题标题】:Parsing Table With Beautiful Soup用美丽的汤解析表
【发布时间】:2013-04-29 17:35:47
【问题描述】:

我正在编写一个程序,该程序可以访问我的学校成绩网站,并将我的成绩作为我的桌面背景,但是一旦我达到我的成绩,我就无法知道如何从大表中解析它们

这是我的代码:

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

【问题讨论】:

  • 它的大量代码试图获取相关部分
  • 这是整张桌子gist.github.com/C-Dubb/5522909
  • 只是第二学期的数字而已
  • 非常感谢您的帮助!!

标签: python parsing selenium beautifulsoup


【解决方案1】:

此资源可能会对您有所帮助:locating elements in selenium

你可以试试

find_element_by_link_text

以及您的一门课程的名称,以获得包含该课程成绩的元素

【讨论】:

    猜你喜欢
    • 2014-08-11
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    相关资源
    最近更新 更多