Engaging with JavaScript objects while utilizing Python and Selenium for web scraping

My current challenge involves loading additional comments by clicking on a JavaScript object and then scraping the page to collect data. To troubleshoot this issue, I am comparing the number of comments displayed before and after clicking the "load more" button within a p tag element. However, I consistently receive the same count for both instances despite the presence of additional comments on the page. Where could my code be incorrect?

from selenium import webdriver
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

driver = webdriver.PhantomJS(executable_path='PATH_TO.../phantomjs')
driver.get('http://www.ratemyprofessors.com/ShowRatings.jsp?tid=1500075')

comments = driver.find_elements_by_tag_name('p')
print('Initial Comment Count:', len(comments))

time.sleep(1)

try:
    element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'loadMore')))
    time.sleep(1)
finally:
    comments = driver.find_elements_by_tag_name('p')
    print('Updated Comment Count:', len(comments))

driver.close()

I have attempted using both 'loadMore' and 'loadmoreBlog' identifiers without success. Any insights or suggestions would be greatly appreciated.

Answer №1

I found a solution by including

element.click()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

utilizing the getElementById for styling a paragraph within a div

Upon hovering over an image, I am looking to make the paragraph within this div disappear. Here's what I've tried: $("#One1 img").hover(function(){ var par = document.getElementById('One1 p'); par.style.display = "none"; },funct ...

Encountered Runtime Issue of TypeError: undefined cannot be iterated (unable to access property Symbol(Symbol.iterator))

I've been working on a multiselect feature in my Next.js project, utilizing states and setting them accordingly. However, I keep encountering this specific error: https://i.stack.imgur.com/m8zuP.png whenever I click on this: https://i.stack.imgur.c ...

Callback Method Ajaxify

Just started using Ajaxify and so far it's been a great experience. However, I'm wondering if there is a callback function available that doesn't require any specific inputs in the script. I've searched around but haven't found wh ...

Attempting to scrape a constantly changing table using a combination of Selenium and Beautiful Soup

I've been attempting to extract data from a complex table generated using chromedriver for automation purposes, followed by an anti-captcha service integration. I came across an example where someone utilized beautiful soup after the table was created ...

Trouble encountered when attempting to send a variable from JavaScript to PHP using Ajax

I am currently developing a calculator web application using PHP. The front end is created with HTML, CSS, and JS. Within my JS file, I am attempting to send a variable to PHP using ajax. Here is a snippet of my progress: // Retrieving all keys from the d ...

JavaScript: Retrieving the names of children within a <div> element

Within my structure setup, there is a tower div with inner elements like this: <div class="tower"> <div class="E0">abc</div> <div class="GU">123</di </div> The challenge I am facing is that I need to access the in ...

Determine whether the keyCode value matches any items within a specific array

Currently, as I am in the process of creating a small typewriter application, I have encountered an issue with determining if the button pressed matches the value of specific span elements. To provide further context, there are two divs each containing sp ...

npm is having trouble locating the module called 'encoding'

I've run into a npm issue on my newly formatted Ubuntu OS laptop while using VSCode. The error I encountered during installation is: npm ERR! code MODULE_NOT_FOUND npm ERR! cannot find module 'encoding' // Log 0 info it worked if it e ...

Utilizing underscore.js to aggregate data points: A comprehensive guide

If I have an array containing 6 numeric data points and I want to transform it into a new array with only 3 data points, where each point is the sum of two of the original points. For example: [1,1,1,1,1,1] would become [2,2,2] What would be the most eff ...

Encountering a 403 Forbidden error when attempting to include a full URL in my JSON data using jQuery and PHP

I am currently working on a project to create a card generator for educational purposes and to have some fun. I am learning how to gather data from user inputs and save it to a database. However, I encountered an issue when trying to send a simple JSON da ...

What is the best way to retrieve properties from a different module in JavaScript?

I have a module named ProgressIndicator: ... export default class ProgressIndicator { constructor() { ... const indicatorGeometry = new THREE.PlaneGeometry(2, 2, 1, 1) const indicatorMaterial = new THREE.ShaderMate ...

Changing URL parameters without refreshing the page using query strings

Is there a method similar to how Google adds and removes parameters from the URL in Gmail without requiring a postback? For example, when you start composing a draft, a "?compose=new" parameter is added to the URL. I was considering using `history.pushSta ...

How can we check if this element is empty using jQuery?

If the <p></p> on the second page is empty, I want to jump from the first page to the third. Or if it's empty on the third page, then jump to the fourth. $(".lr1").click(function() { $(".p1").slideUp("fast"); $(".p2").slideDown("fas ...

Creating a split-view menu in WinJS: A step-by-step guide

I'm attempting to create a versatile app using JavaScript. I followed a tutorial on the MSDN website, but for some reason, the "nav-commands" class isn't displaying when the splitview is opened. I have set closedDisplayMode = 'none'. & ...

What are the implications of declaring a controller as a variable within itself or utilizing $scope?

As I dive into learning and utilizing AngularJS, certain concepts still remain unclear to me. Here is my query: within my application, there is a controller that utilizes $http to fetch data from the backend upon initialization. Following a comprehensive ...

The child component's template content fails to display properly within the parent component hosting it

Currently, I am utilizing Vue3 with options api in the code snippet below. Within my parent component, I have embedded a child component as demonstrated. The issue arises during runtime where even though showNotificationsWindowsContainer is set to true, t ...

Troubleshooting a jQuery gallery slider glitch

I have implemented a photo gallery from Codrops to showcase images on my website. Instead of manually inputting the image links into the html, I have utilized a PHP script to dynamically display images from a specific directory. My goal is to trigger the p ...

What is the best way to fetch a request in express.js without navigating away from the current page

How can I make my express server interact with the file system (fs) when the upload or download button is clicked, without refreshing the web page? Can you show me how to implement this in JavaScript? let express = require('express'); let fs = re ...

Tips for updating Angular HTML with data received from Socket.IO

I am currently working on a socket program that is listening and providing log data. The socket is sending the correct data as I can see it in the console. Below is a snippet of my code: export class RoboLogComponent implements OnInit { dataToShow:any @V ...

Selenium can sometimes locate only a small number of elements

I am currently developing a recommendation system for webtoons, and to do so, I am gathering data on various webtoons. My latest task involved writing a script to scrape the URLs of webtoons on the Kakao Webtoon page. def extract_from_page(page_link): ...