I tried to click "More" button for each review so that I can expand these text reviews to the full contents and then I try to scrape those text reviews. Without clicking "More" button, what I end up retrieving is something like
"This room was nice and clean. The location...More".
I tried a few different functions to figure it out such as selenium button click and ActionChain but I guess I'm not using these properly. Could someone help me out with this issue?
Below is my current code: I didn't upload the whole code to avoid some unnecessary outputs (tried to make it simple).
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver import ActionChains
#Incognito Mode
option=webdriver.ChromeOptions()
option.add_argument("--incognito")
#Open Chrome
driver=webdriver.Chrome(executable_path="C:/Users/chromedriver.exe",chrome_options=option)
#url I want to visit.
lists=['https://www.tripadvisor.com/VacationRentalReview-g30196-d6386734-Hot_51st_St_Walk_to_Mueller_2BDR_Modern_sleeps_7-Austin_Texas.html']
for k in lists:
driver.get(k)
html =driver.page_source
soup=BeautifulSoup(html,"html.parser")
time.sleep(3)
listing=soup.find_all("div", class_="review-container")
for i in range(len(listing)):
try:
#First, I tried this but didn't work.
#link = driver.find_element_by_link_text('More')
#driver.execute_script("arguments[0].click();", link)
#Second, I tried ActionaChains but didn't work.
ActionChains(driver).move_to_element(i).click().perform()
except:
pass
text_review=soup.find_all("div", class_="prw_rup prw_reviews_text_summary_hsx")
text_review_inside=text_review[i].find("p", class_="partial_entry")
review_text=text_review_inside.text
print (review_text)
except: pass. Without this you would resolve problem long time ago. Code raise error message with all information but you can't see it.