Python 无法使用Selenium从网页中定位文本

Python 无法使用Selenium从网页中定位文本,python,css,selenium,webdriverwait,Python,Css,Selenium,Webdriverwait,我正试图为某个产品搜集亚马逊的评论,但我无法使用selenium找到评级文本。但是同样的东西很容易用汤刮去 链接至第页: 下面是我使用Soup的代码: link='same link as mentioned above' url=requests.get(link).content bs=soup(url,'html.parser') for i in bs.find_all('span',{'class':'a-icon-alt'}): print(i.text.split

我正试图为某个产品搜集亚马逊的评论,但我无法使用selenium找到评级文本。但是同样的东西很容易用汤刮去

链接至第页:

下面是我使用Soup的代码:

 link='same link as mentioned above'
 url=requests.get(link).content
 bs=soup(url,'html.parser')
 for i in bs.find_all('span',{'class':'a-icon-alt'}):
    print(i.text.split(' ')[0])   
##输出 4.3 5 1 5 2 4 1 5 5 5 5 5 5.0

以下是我使用Selenium的代码:

import time
from selenium import webdriver
from bs4 import BeautifulSoup as soup
import requests

link='link to the above mentioned page'
driver=webdriver.Chrome()
driver.get(link)
for i in driver.find_elements_by_css_selector('.a-icon-alt'):
     print(i.text)

我无法使用Selenium获得相同的结果,我得到的只是与该页面上的项目数相等的空白。我也尝试过使用XPath和class_name,但没有得到所需的响应。

要获得评论评级,请导入
WebDriverWait
,等待
所有位于
()的元素出现,并使用
get_属性(“innerHTML”)

代码

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

link='https://www.amazon.in/BenQ-inch-Bezel-Monitor-Built/product-reviews/B073NTCT4R/ref=cm_cr_arp_d_paging_btm_next_2?ie=UTF8&reviewerType=all_reviews&pageNumber=39'
driver=webdriver.Chrome()
driver.get(link)
elements=WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".a-icon-alt")))
for i in elements:
    print(i.get_attribute("innerHTML").split(' ')[0])
控制台上的输出:

4.3
5.0
1.0
5.0
2.0
4.0
1.0
5.0
5.0
5.0
5.0
5.0
5.0