R Web Scraping: Navigating Dynamic Web Pages with AJAX Button Clicks

Is there a way to modify the R code below in order to extract Quarterly data? I am attempting to retrieve data from Yahoo Finance, which is a dynamic web page using AJAX, resulting in the same address for both Annual and Quarterly data. The selector to use is 'button.P\(0px\)'. While I have successfully extracted the Annual data for the Income Statement table for AAPL, I am facing challenges in retrieving Quarterly data. Any guidance or suggestions would be greatly appreciated :)

library(rvest)
url <- 'https://finance.yahoo.com/quote/AAPL/financials?p=AAPL'
webpage <- read_html(url)
tableIS <- html_table(html_nodes(webpage,'table.Lh\\(1\\.7\\)'), header = NA, trim = TRUE, fill = FALSE, dec = ".")
print (tableIS)

Answer №1

If you're looking to head in the right direction, this can help.

data <- read.csv("http://financials.morningstar.com/ajax/ReportProcess4CSV.html?&t=XNAS:AAPL&region=usa&culture=en-US&cur=&reportType=is&period=3&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=865827&denominatorView=raw&number=3", skip=1)
print(data)

Here's something else you might find interesting.

# check out these financial metrics and ratios
read.csv("http://financials.morningstar.com/ajax/exportKR2CSV.html?&t=AAPL",header=T,stringsAsFactors = F,skip = 2)[,-c(12)]->spreadsheet
View(spreadsheet)

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

Troubleshooting Problems with Magento's Cart Ajax Feature

I have successfully implemented an Ajax-based button on the product listing page to add products. However, I am facing issues with updating the cart displayed at the top of the page. I need assistance in updating the cart as well. The cart PHTML file can ...

Combine two or more Firebase Observables

Currently, I am working on creating an Observable using FirebaseObjectObservable. However, before I can accomplish this, I need to query a Firebase list to obtain the key IDs required for the FirebaseObjectObservable. The structure of my data is as follow ...

Execute the second method once the first method has completed its execution

As I develop my npm package, I am faced with the challenge of ensuring that one method waits for another to complete before executing. For example: var package = require('myNpmPackage'); package.method1(options); ... Later on, possibly in a dif ...

Error Occurred while Uploading Images using Ajax HTML Editor with JSON Data

I am facing an issue with my AJAX HtmlEditorExtender, specifically when trying to upload an image. The error message I receive is as follows: JavaScript runtime error: Sys.ArgumentException: Cannot de-serialize. The data does not correspond to valid JSON. ...

Refreshing various innerHTML elements using a universal function

I'm attempting to consolidate several similar functions into one, but I'm encountering some challenges. Below is an example of one of the original functions that is called by a button press: function ADD_ONE(Variable_Name){ Variable_Name += ...

Implementing Ajax functionality in MVC 3 to return a partial view

I wanted to express my gratitude for this invaluable site that has taught me so much. Currently, I am working on an MVC3 component where I need to populate a selectlist and upon user selection, load a partial view with the relevant data displayed. Everythi ...

Warning occurs when trying to access frame with URL in JavaScript; issue arises in poltergeist but not selenium-webdriver

I've been using Selenium-Webdriver as the javascript driver for running Cucumber tests on my Rails app and had consistent results. Recently, I decided to switch to Poltergeist to run headless. Some of my tests involve a Stripe transaction that trigge ...

When there is content behind the list, the Autosuggest Ajax does not function properly

I have successfully implemented an ajax/jquery dropdown/list feature that retrieves results from the database based on user input. For each result in the database, it generates a <li> element and converts it into a clickable link to redirect users t ...

Unable to transmit the search query as a parameter

I am working on a dropdown display with autocomplete feature using the select2 jQuery plugin. However, I have encountered an issue where the search term entered in the search box is not being passed as a parameter to the controller method. Here is my curre ...

JSON.stringify not behaving as anticipated

I am working on the code below; var data = []; data['id'] = 105; data['authenticated'] = true; console.log(data); var jsonData = JSON.stringify(data); console.log(jsonData); The initial console.log is displaying; [id: 105, authenti ...

An issue arose during the page prerendering process for "/" on Vercel | Next.js resulting in a deployment error

When attempting to deploy my website using Vercel and generating static pages, I encountered the following error in the logs: info - Generating static pages (0/6) Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/ ...

Creating input fields dynamically within Yii2 framework

I'm currently facing a challenge with forms in Yii2. My objective is to design a form that includes three dropdown menus, inquiring about the user's preferred time(s) during the week. The first menu will focus on selecting days of the week, while ...

PHP Email Form Sending Duplicate Emails to Recipients

My PHP mail form is set up to use AJAX & jQuery for validation and submission. Everything appears to be working fine, but the client receiving multiple copies of each email sent by the form. The number of duplicates ranges from 1 to 10 with no clear pa ...

Tips for implementing the select all feature in mat-checkbox for Angular 5

Here is the code snippet from my HTML template: <mat-card> <mat-card-content> <h2 class="example-h2">Select Employee</h2> <section class="example-section"> <mat-checkbox [(ngModel)]="ch ...

Surprising pause in the menu transition animation

Currently, I am in the process of developing a menu that seems to have some flaws. One issue is that it appears a bit choppy, but the more concerning problem is the half-second delay after clicking an item before it animates. The concept behind this menu ...

Creating a Countdown in Javascript Using a Variable

I want the date to change from the first date to the second date. At the start, it should display 'Starts:' in bold followed by the remaining time. Once it switches to the second date, it should show 'Ends:' in bold and then the remaini ...

Implementing multiple content changes in a span using javascript

Having an issue with a pause button where the icon should change on click between play and pause icons. Initially, the first click successfully changes the icon from a play arrow to a pause icon, but it only changes once. It seems like the else part of the ...

What is the best way to use ajax with jquery for file uploading?

Is it possible to use jQuery and ajax to upload an image with this code or something similar? jQuery.ajax({ type: "GET", url: "/userinfo/update/", dataType: "json", data: { ...

The conditional statement for ajax is malfunctioning

I am encountering an issue with some ajax coding. The if condition is not working as expected - whenever the program runs, only the else statement gets executed even when the if statement should be satisfied. <script type="text/javascript> funct ...

Mapping data points alongside raster data

After plotting a dataframe of points using the plot function, I am now looking to incorporate a RasterLayer of AnnualTemp. Can you provide assistance with finalizing the code? library(raster) MinTemp_plots <- data.frame( Station = c( "Labasa&q ...