[英]Get the text contained in all the tag having the attribute specify as "<div class='wld' text >" with the WebDriver Selenium in python
I would like to recieve the "text" contained in all the <div class='wld' text >
.我想收到包含在所有
<div class='wld' text >
。 I tried this code :我试过这个代码:
match_results = driver.find_elements(By.CSS_SELECTOR, ".wld").text
print(match_results)
and this和这个
match_results = driver.find_elements(By.CSS_SELECTOR, ".wld")
print(match_results.text)
and as well try the methods answered this question How to get text with selenium web driver in python that resemble the method that I did more high.并尝试回答这个问题的方法如何在 python中使用 selenium web 驱动程序获取文本,类似于我做的更高的方法。
I get this error message :我收到此错误消息:
match_results = driver.find_elements(By.CSS_SELECTOR, ".wld").text
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'text'
and this和这个
print(match_results.text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'text'
When I Remove .text
here is what this当我删除
.text
这里是什么
[<selenium.webdriver.remote.webelement.WebElement (session="409c9b33d38ef268b14fe6f18992b61c", element="2321a252-8cb9-4fd1-8f8a-af837c28b35c")>,
and this for each element "text" contained in <div class='wld' text >
What can I do for display all the "text", method to used ?这对于
<div class='wld' text >
包含的每个元素“文本”我可以做什么来显示所有“文本”,使用的方法? I'm heard that it would have to through BeautifulSoup in others forum, your notice ?我听说它必须通过其他论坛的 BeautifulSoup,您注意到了吗?
Important information that I forgeted of precis : it is that I arrive to access the first element of way individual with method driver.find_element(By.CSS_SELECTOR, ".wld").text
for exemple and.我忘记了 precis 的重要信息:例如,我使用方法
driver.find_element(By.CSS_SELECTOR, ".wld").text
访问方式个体的第一个元素。
'find_elements' method will return a list of elements and it does not have 'text' attribute. 'find_elements' 方法将返回一个元素列表,它没有 'text' 属性。
So if you want to get list of elements try this.因此,如果您想获取元素列表,请尝试此操作。
match_results = driver.find_elements(By.CSS_SELECTOR, ".wld")
for elem in match_results:
print(elem.text)
Or if you want to get only one element try this.或者,如果您只想获取一个元素,请尝试此操作。
match_results = driver.find_element(By.CSS_SELECTOR, ".wld").text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.