楼主: 华月天心
2589 14

[学习分享] 用R爬取奥克兰大学的R语言教程 [推广有奖]

11
沁舞怜 发表于 2019-5-19 00:26:12

请帮忙看看, 只能抓到第一个pdf, 显示如下:
Warning messages:
1: In if (grepl("^https?://", url)) { :
  the condition has length > 1 and only the first element will be used
2: In if (grepl("^https?://", url)) { :
  the condition has length > 1 and only the first element will be used
3: In if (grepl("^https?://", url)) { :
  the condition has length > 1 and only the first element will be used
我也是这样

12
wind2599 发表于 2019-5-19 07:01:44
沁舞怜 发表于 2019-5-19 00:26
请帮忙看看, 只能抓到第一个pdf, 显示如下:
Warning messages:
1: In if (grepl("^https?://", url)) { ...
download(link,paste("E:/R/",numb,sep = ""), mode = "wb")
把download行代码加两个i就好了

13
zhou1_20 发表于 2019-5-19 09:08:13
给一个简略版,请参考
  1. library(rvest)
  2. obj <- (read_html('https://www.stat.auckland.ac.nz/~ihaka/120/Lectures/')%>%
  3.           html_nodes('td:nth-child(2) > a')%>%
  4.           html_attr('href'))[-1]
  5. dir.create('C:\\z\\R_lectures')
  6. setwd('c:/z/R_lectures/')
  7. lapply(obj, function(x) paste0(url,x)%>%
  8.          download.file(destfile=x, mode = "wb"))
复制代码

14
华月天心 发表于 2019-5-19 10:12:24
lyfyb99 发表于 2019-5-14 10:48
请帮忙看看, 只能抓到第一个pdf, 显示如下:
Warning messages:
1: In if (grepl("^https?://", url)) { : ...
可以看一下10楼的回复

15
lyfyb99 在职认证  发表于 2019-5-31 23:46:25
wind2599 发表于 2019-5-19 00:20
download(link,paste("E:/R/",numb,sep = ""), mode = "wb")
应该是这样吧?
可以了,多谢指教!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 17:44