简体   繁体   English

从 R 中的网络抓取中提取数据的效率

[英]Efficiency in extracting data from webscraping in R

This is no doubt very simple so apologies but I am new to webscraping and am trying to extract multiple datapoints in one call using rvest.毫无疑问,这非常简单,所以很抱歉,但我是网络抓取的新手,我正在尝试使用 rvest 在一次调用中提取多个数据点。 Let's take for example the following code (NB I have not used the actual website which I have replaced in this code snippet with xxxxxx.com):让我们以下面的代码为例(注意我没有使用我在这个代码片段中用 xxxxxx.com 替换的实际网站):

univsalaries <- lapply(paste0('https://xxxxxx.com/job/p', 1:20,'/key=%F9%80%76&final=1&jump=1&PGTID=0d3408-0000-24gf-ac2b-810&ClickID=2'),
                   function(url_base){
                     url_base %>% read_html() %>% 
                       html_nodes('.salary') %>% 
                       html_text()
                   })

Read the webpage once and then you can extract multiple values from the same page.阅读网页一次,然后您可以从同一页面中提取多个值。

library(purrr)
library(rvest)

univsalaries <- map(paste0('https://xxxxxx.com/job/p', 1:20,'/key=%F9%80%76&final=1&jump=1&PGTID=0d3408-0000-24gf-ac2b-810&ClickID=2'),
                       function(url_base){
                         webpage <- url_base %>% read_html() 
                         data.frame(Salary = webpage %>% html_nodes('.salary') %>% html_text(), 
                                    Company = webpage %>% html_nodes('.company') %>% html_text())
                       })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM