python - 如何在 Python 中使用 Selenium 提取文本元素?

标签 python selenium class xpath

考虑:

Enter image description here

我正在使用 Selenium 从 App Store 中抓取内容: https://apps.apple.com/us/app/bank-of-america-private-bank/id1096813830

我尝试提取文本字段“作为主题专家,我们的团队非常有吸引力......”

我试图按类别查找元素

review_ratings = driver.find_elements_by_class_name('we-truncate we-truncate--multi-line we-truncate--interactive ember-view we-customer-review__body')
review_ratingsList = []
for e in review_ratings:
review_ratingsList.append(e.get_attribute('innerHTML'))
review_ratings

但它返回一个空列表[]

代码有问题吗?或者有更好的解决方案吗?

最佳答案

使用 RequestsBeautiful Soup :

import requests
from bs4 import BeautifulSoup

url = 'https://apps.apple.com/us/app/bank-of-america-private-bank/id1096813830'

res = requests.get(url)
soup = BeautifulSoup(res.text,'lxml')
item = soup.select_one("blockquote > p").text
print(item)

输出:

As subject matter experts, our team is very engaging and focused on our near and long term financial health!

关于python - 如何在 Python 中使用 Selenium 提取文本元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57209066/

相关文章:

python - gcc 错误输出未定向到文件

selenium - SpecFlow + Selenium-WebDriver : Sharing a WebDriver Across Steps?

java - Selenium ChromeDriver 返回未知错误 : unable to discover open pages

node.js - Selenium Node + Sauce 实验室测试 : Cannot Finish a Task

c++ - 将 vector 与对象一起使用错误

python - SQLAlchemy 关系之间的差异

Python 选择有条件的元组

java - 创建未知数量对象实例的有效方法

c++ - 如何制作包含 "Private"?

python - 在 C 中调用从 Python 接收函数指针的函数