[英]how do I select the div that has this <i> using Selenium python
I want to scrape a quiz with selenium using python, here's the code for 1 answer choice.我想使用 python 用 selenium 进行测验,这是 1 个答案选择的代码。
the will contains this specific class when it's correct answer , and when its not correct it is another class for this当它是正确答案时,遗嘱包含这个特定的类,当它不正确时,它是另一个类
so I want to get the text of the question where the answer is correct (The product's impact on customer satisfaction.) It will depends of the class inside the < i > (because as I said, when its false answer, it's another class inside )所以我想得到答案正确的问题文本(产品对客户满意度的影响。)这将取决于 < i > 里面的类(因为正如我所说,当它的错误答案时,它是里面的另一个类)
But I can't find how to select it with XPATH但我找不到如何使用 XPATH 选择它
<div class='course-player__interactive-checkbox _interactive-checkbox_cjbh9b'>
<div class='course-player__interactive-checkbox__choice-label _interactive-checkbox__choice-label_cjbh9b'>
<span class='course-player__interactive-checkbox__choice-letter _interactive-checkbox__choice-letter_cjbh9b'> ANSWER A </span>
</div>
<span class='course-player__interactive-checkbox__choice-text _interactive-checkbox__choice-text_cjbh9b'> The product's impact on customer satisfaction. </span>
<span class='course-player__interactive-checkbox__choice-answered _interactive-checkbox__choice-answered_cjbh9b'>
<i class='toga-icon toga-icon-circle-fill-check _interactive-checkbox__choice-icon_cjbh9b'> </i>
</span>
</div>
One approach to retrieve the string一种检索字符串的方法
The product's impact on customer satisfaction.
产品对客户满意度的影响。
with Selenium is the following: Selenium 如下:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("file:///input.html")
lookup = driver.find_elements_by_xpath("//div/span[i]/preceding-sibling::*[1]")
print(lookup[0].text)
The XPath-1.0 expression selects the <span>
before the <span>
which has an <i>
child. XPath-1.0 表达式选择
<span>
之前的<span>
,它有一个<i>
子节点。
But be aware that this code does not contain any error handling.但请注意,此代码不包含任何错误处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.