我正在尝试使用 XPaths 获取 HTML 表的内容,我正在使用 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"]
我会发布我正在尝试解析的 HTML,但它非常长,而且从我所使用的其他一些网站的情况来看,它的编写非常草率