现在,我正在开发一个程序,它接受用户输入的问题和答案,将它们分成Q和a的单独列表,然后自动回答问题,给出问题或答案。由于使用'bot‘的地方是在线的,我使用的是Selenium web驱动程序,这给我在试图读取咏叹号时带来了一些问题。我不知道我做错了什么,因为我对selenium、HTML或CSS一点也不先进。我试图找出每个容器的aria标签值,而不知道它是什么。
--我正在尝试获取的文本值:的一个例子
<div class="MatchModeQuestionGridBoard-tile"><div class="MatchModeQuestionGridTile" touch-action="auto"><div class="MatchModeQuestionGridTile-content"><div aria-label="to cloak; to conceal the truth; to offer lame excuses" class="FormattedText notranslate TermText MatchModeQuestionGridTile-text lang-en" style="font-size: 14px;"><div style="display: block;">to cloak; to conceal the truth; to offer lame excuses</div></div></div></div></div>
我的代码的片段:
def driver():
driver = webdriver.Chrome()
driver.get(link)
startMatch = driver.find_element_by_xpath("/html/body/div[5]/div/div/div/div[2]/button").click()
#find text in matches
container = driver.find_elements_by_class_name('MatchModeQuestionGridTile-content')
containerFile = open("QuizletTerms.txt", "w+")
for _ in list(container):
arialabel = driver.find_elements_by_css_selector("div[aria-label='']")
containerFile.write("\n")
containerFile.write(str(arialabel))
print(arialabel)
containerFile.close()
print("done")
sleep(5)
输出:
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
发布于 2020-09-17 21:27:18
这些文本,如来掩盖真相,提供蹩脚的借口,在<div>
中也出现在它的父母<div>
中。因此,提取它,您需要为visibility_of_all_elements_located()
导出visibility_of_all_elements_located()
,您可以使用以下任何一个Locator Strategies
CSS_SELECTOR
和get_attribute()
:打印([my_elem.get_attribute(“aria-标签”)用于my_elem in WebDriverWait)(驱动程序,WebDriverWait)
XPATH
和get_attribute()
:打印([my_elem.get_attribute(“aria-标签”)用于my_elem in WebDriverWait)(驱动程序,WebDriverWait)
从selenium.webdriver.support.ui导入WebDriverWait从selenium.webdriver.common.by导入从selenium.webdriver.support导入expected_conditions作为EC
https://stackoverflow.com/questions/63946115
复制相似问题