ResultSet 对象没有属性 'text'。您可能将项目列表视为单个项目。

ResultSet object has no attribute 'text'. You're probably treating a list of items like a single item.

        from selenium import webdriver      
        from selenium.common.exceptions import NoSuchElementException
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support.ui import WebDriverWait
        from selenium.webdriver.support import expected_conditions as EC
        import time
        from bs4 import BeautifulSoup


        #browser = webdriver.Firefox()#Chrome('./chromedriver.exe')
        YOUTUBER_HOME_PAGE_URL = "https://www.imdb.com/title/tt6452574/reviews?ref_=tt_ov_rt"
        PATIENCE_TIME = 60
        LOAD_MORE_BUTTON_XPATH = '//*[@id="load-more-trigger"]' 

        driver = webdriver.Chrome(r"C:\Users\Panu\Dropbox\Dr.Gokhan Sir\chromedriver.exe")
        driver.get(YOUTUBER_HOME_PAGE_URL)

        while True:
            try:
                loadMoreButton = driver.find_element_by_xpath('//*[@id="load-more-trigger"]')
                time.sleep(2)
                loadMoreButton.click()
                time.sleep(5)
            except Exception as e:
                print e
                break
        print "Complete"
        time.sleep(10)
        #Selenium hands the page source to Beautiful Soup
        soup_level1=BeautifulSoup(driver.page_source, 'html.parser')

    movie_containers = soup_level1.find_all('div', class_ = 'review-container')
    print(type(movie_containers))
    print(len(movie_containers))
sample_data = movie_containers
#div = sample_data.find_all('div', class_ = 'text show-more__control')
#sample_data.text for user review and titile
reviews = []
user_titles = []
for div in sample_data:
    title = div.div.a.text
    user_titles.append(title)
    #print(div.text)
    review = div.find_all('div', class_ = 'text show-more__control').text
    reviews.append(review)

我在运行上面的代码时出错。 AttributeError: ResultSet 对象没有属性 'text'。您可能将项目列表视为单个项目。当您打算调用 find() 时,您是否调用了 find_all()?

您的线路:

review = div.find_all('div', class_ = 'text show-more__control').text

导致了问题。 div.find_all 将 return 所有具有 class 的 div 作为列表对象。然后,您将对该列表对象调用 .text。 python 怎么知道你想看哪个文本?用类似的东西遍历你的结果:

divs = div.find_all('div', class_ = 'text show-more__control')

for div in divs:
    #inside of this loop you will be accessing each review
    print(div)
    print("") #doing this to print a blank line to "separate" them for you

然后使用你想要的。