Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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:
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)
i got error while runing above code. AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
–
is causing the problem. div.find_all will return all divs with that class as a list object. You're then calling .text on that list object. How does python know which text you want to see? Iterate through your results with something like:
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
Then use the ones you want.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.