python硒从元素获取文本

exec85

我如何从该HTML树中提取文本“总理联赛(ENG 1)”?(标记部分)在此处输入图片说明

我用xpath,css选择器,类来获取文本,但我似乎无法提取该文本。

基本上,我想创建一个列表并遍历所有包含文本(“联盟”)的“带有图标的class”元素,并将文本附加到该列表中。

这是我最后的尝试:

def scrape_test():
    alleligen = []

    #click the dropdown menue to open the folder with all the leagues
    league_dropdown_menue = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[7]/div')
    liga_dropdown_menue.click()
    time.sleep(1)
    
    #get text form all elements that conain a league as text
    leagues = driver.find_elements_by_css_selector('body > main > section > section > div.ut-navigation-container-view--content > div > div.ut-pinned-list-container.ut-content-container > div > div.ut-pinned-list > div.ut-item-search-view > div.inline-list-select.ut-search-filter-control.has-default.has-image.is-open.active > div > ul > li:nth-child(3)')
    
    #append to list
    alleligen.append(leagues)
    
    print(alleligen)

但是我没有任何输出。

我在这里想念什么?

(我是编码新手)

拉胡莱

你能试一下吗 :

leagues = driver.find_elements_by_xpath(“//li[@class=‘with-icon’ and contains(text(), ‘League’)]”)
For league in leagues:
     alleligen.append(league.text)
print(alleligen)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章