【发布时间】:2022-01-20 17:44:44
【问题描述】:
我试图在一个元素下分别打印 2 个文本文件,但因为我无法直接使用 selenium 选择文本文件(如第 1 个文本、第 2 个文本)
我想单独选择“主场胜利”“PSV vs Ajax”
我的代码:
driver.get("https://footystats.org/predictions/home-wins")
matches = driver.find_elements_by_xpath("//div[@class='predictionsList']//div[@class='betWrapper ']//div[@class='betHeaderTitle']/text()")
predictions = driver.find_elements_by_xpath("//div[@class='predictionsList']//div[@class='betWrapper ']//span[@class='market']")
odds = driver.find_elements_by_xpath("//div[@class='predictionsList']//div[@class='betWrapper ']//div[@class='betHeaderMeta']")
for x in range(0,len(matches)):
print(matches[x].text, predictions[x].text, odds[x].text, sep="\t")
如果我这样编写代码,则会出错;
The result of the xpath expression is: [object Text]. It should be an element.
如果我从 'matches' 元素中删除 '/text()',它一次需要 2 个文本。
【问题讨论】: