簡體   English   中英

使用R進行網頁抓取-如何使用AJAX在動態網頁中單擊按鈕?

[英]Web scraping with R - How to click on a button in a dynamic web page using AJAX?

如何修改以下R代碼以提取每季度數據? 我正在嘗試從Yahoo Finance獲取數據,Yahoo Finance是使用AJAX的動態網頁,因此,年度和季度數據的地址均相同。 選擇器為“ button.P \\(0px \\)”。 到目前為止,我已經設法提取了APL的損益表中的年度數據,但仍在努力獲取季度數據。 任何建議都歡迎:)

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)

這應該使您朝正確的方向前進。

result <- 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(result)

您可能也對此感興趣。

# 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM