簡體   English   中英

將 Javascript 呈現的網頁內容讀入 R

[英]Reading the content of a Javascript-rendered webpage into R

我正在嘗試將以下網頁的內容(如瀏覽器的 Inspect Element 工具中所示)讀入 R:

Etoro 發現人

由於內容顯然是 Javascript 渲染的,因此無法使用常見的 web 抓取函數(如來自xml2 read_html的 read_html)來檢索內容。 我遇到了以下建議使用rvestV8包的帖子,但我無法解決我的問題:

https://datascienceplus.com/scraping-javascript-rendered-web-content-using-r/

我在 Stack Overflow 上也看到了非常相似的問題(比如thisthis ),但是這些問題的答案(隱藏的 api 解決方案和 Network 選項卡中的 Request URL )對我不起作用。

對於初學者,我有興趣閱讀列表中人員的公共 ID( div.user-nickname節點)。 我的猜測是,要么我錯誤地指定了節點,要么網站根本不允許 web 抓取。

任何幫助將不勝感激。

數據來自返回 json 的 API 調用。 您可以發出相同的 GET 請求,然后提取用戶名。 x$UserNamex$CustomerId交換為 id。

library(jsonlite)

data <- jsonlite::read_json('https://www.etoro.com/sapi/rankings/rankings/?activeweeksmin=24&blocked=false&bonusonly=false&copiersmax=5000&copyblock=false&copyinvestmentpctmax=0&copytradespctmax=0&dailyddmin=-10&displayfullname=true&gainmax=100&gainmin=5&hasavatar=true&highleveragepctmax=10&isfund=false&istestaccount=false&lastactivitymax=14&longpospctmax=80&lowleveragepctmin=50&maxdailyriskscoremax=5&maxmonthlyriskscoremax=5&maxmonthlyriskscoremin=1&optin=true&page=1&pagesize=20&period=OneYearAgo&profitableweekspctmin=50&sort=-gain&tradesmin=20&verified=true&weeklyddmin=-20&winratiomax=85')

users <- lapply(data$Items, function(x) {x$UserName})

暫無
暫無

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

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