如何使用 XPATH 解析此 HTML table?

How can I parse this HTML table using XPATHs?

我正在尝试使用 XPaths 获取 HTML table 的内容,我正在使用 Mechanicalsoup 获取表单并提交一次(数据在提交表单后面)我点击了第二种形式,我抓住了 URL 并将其传递给解析,但我得到了 AttributeError: 'list' object has no attribute 'xpath'

import mechanicalsoup
import requests
from lxml import html
from lxml import etree


#This Will Use Mechanical Soup to grab the Form, Subit it and find the Data Table
browser = mechanicalsoup.StatefulBrowser()
winnet = "http://winnet.wartburg.edu/coursefinder/"
browser.open(winnet)
Searchform = browser.select_form()
Searchform.choose_submit('ctl00$ContentPlaceHolder1$FormView1$Button_FindNow')
response1 = browser.submit_selected() #This Progresses to Second Form
dataURL = 'https://winnet.wartburg.edu/coursefinder/Results.aspx' #Get URL of Second Form w/ Data


pageContent=requests.get(dataURL)
tree = html.fromstring(pageContent.content)
dataTable = tree.xpath('//*[@id="ctl00_ContentPlaceHolder1_GridView1"]')
print(dataTable)
for row in dataTable.xpath(".//tr")[1:]:
    print([cell.text_content() for cell in row.xpath(".//td")])

#XPath to Table
#//*[@id="ctl00_ContentPlaceHolder1_GridView1"]

我会 post HTML 我正在尝试解析,但它非常长,而且从我所看到的其他一些我使用过的网站来看,它非常草率写的

我不确定,但我相信你正在寻找这样的东西。如果不是这样,您可能可以修改它以到达您想要的位置。

import pandas as pd
rows = [] #initialize a collection of rows
for row in dataTable[0].xpath(".//tr")[1:]: #add new rows to the collection
    rows.append([cell.text_content().strip() for cell in row.xpath(".//td")])

df = pd.DataFrame(rows) #load the collection to a dataframe
df

输出(请原谅格式):

View Details AC 121 01 Principles of Accounting I Pilcher, A M W F 10:45AM-11:50AM 45/40/0 WBC 116 2019-20 WI 1.00

View Details AC 122 01 Principles of Accounting II Pilcher, A MWF 12:00PM-1:05PM 45/42/0 WBC 116 2019-20 WI 1.00

等等