简体   繁体   English

我想通过 python selenium 从“aria-label”获取文本

[英]I want to get text from "aria-label" by python selenium

try:
    Rating = driver.find_elements(By.CSS_SELECTOR,'div.b5cd09854e.d10a6220b4')
except:
    Rating = None
Rating1 = []
for i in Rating:
    store = {
        'Rating': i.get_attribute("[aria-label]")
    }
    Rating1.append(store)
print(Rating1)

Output输出

<selenium.webdriver.remote.webelement.WebElement (session="867a6f4433baacd665edd311671faa81", element="69d53b22-5d2e-4e1a-8f55-682affc043b1")>

I want scrape data from a website but I can't extract "aria-label" web elements text by python selenium.我想从网站上抓取数据,但无法通过 python selenium 提取"aria-label"网络元素文本。 please experts help me to extract "aria-label" web elements to get text from it.请专家帮助我提取"aria-label"网络元素以从中获取文本。 fix it and rewrite修复并重写

so to get hold of the text you just use the .text .因此,要获取文本,您只需使用.text即可。

Like so:-像这样:-

Rating = driver.find_elements(By.CSS_SELECTOR,'div.b5cd09854e.d10a6220b4')
    
for i in Rating:
   print(i.text)

Hope this helps:)希望这可以帮助:)

just use () instead of also using [] inside ().只需使用 () 而不是在 () 中也使用 []。

So your code should be like this.所以你的代码应该是这样的。 . .

try:
    Rating =driver.find_elements(By.CSS_SELECTOR,'div.b5cd09854e.d10a6220b4')
except:
    Rating = None
Rating1 = []
for i in Rating:
    store = {
        'Rating': i.get_attribute("aria-label")
    }
    Rating1.append(store)
print(Rating1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM