相关疑难解决方法(0)

无法在Ubuntu 11.04中安装R包

我是Linux和R的新手.

我在Ubuntu 11.04中安装了R 2.12.今天我尝试安装一个新包,所以我运行了以下命令:

install.packages('XML')
Run Code Online (Sandbox Code Playgroud)

但安装失败并提供以下信息:

* installing *source* package ‘XML’ ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to …
Run Code Online (Sandbox Code Playgroud)

xml installation ubuntu r

125
推荐指数
2
解决办法
7万
查看次数

R:检查url的存在,httr:GET()和url.exists()的问题

我有一个大约13,000个URL的列表,我想从中提取信息,但是,并非每个URL实际存在.事实上,大多数人没有.我刚尝试通过所有13,000个网址,html()但需要很长时间.我试图找出如何在解析它们之前查看url是否实际存在html().我已经尝试使用httrGET()功能,以及rcurlsurl.exists()功能.由于某种原因,即使URL确实存在,也url.exist()始终返回FALSE值,并且我使用的方式GET()总是返回成功,我认为这是因为页面被重定向.

以下URL表示我正在解析的页面类型,第一个不存在

urls <- data.frame('site' = 1:3, 'urls' = c('https://www.deakin.edu.au/current-students/unitguides/UnitGuide.php?year=2015&semester=TRI-1&unit=SLE010', 
                            'https://www.deakin.edu.au/current-students/unitguides/UnitGuide.php?year=2015&semester=TRI-2&unit=HMM202',
                            'https://www.deakin.edu.au/current-students/unitguides/UnitGuide.php?year=2015&semester=TRI-2&unit=SLE339'))

urls$urls <- as.character(urls$urls)
Run Code Online (Sandbox Code Playgroud)

因为GET(),问题是第二个URL实际上并不存在,但它被重定向,因此返回"成功".

 urls$urlExists <- sapply(1:length(urls[,1]), 
                     function(x) ifelse(http_status(GET(urls[x, 'urls']))[[1]] == "success", 1, 0))
Run Code Online (Sandbox Code Playgroud)

因为url.exists(),即使第一个和第三个URL确实存在,我也会返回三个FALSE.

 urls$urlExists2 <- sapply(1:length(urls[,1]), function(x) url.exists(urls[x, 'urls']))
Run Code Online (Sandbox Code Playgroud)

我查了一下这两个职位1,2,但我宁愿不使用的用户代理,只是因为我不知道如何找到我的,或者它是否会使用其他计算机上的验证码不同人的变化.因此,使代码更难以被其他人接收和使用.两篇帖子的答案建议使用GET()in httr.这似乎GET()是首选的方法,但我需要弄清楚如何处理重定向问题.

在解析它们之前,任何人都可以建议在R中测试URL的存在html()吗?我也很乐意为此问题提出任何其他建议的工作.

更新:

在查看了返回的值后,GET()我想出了一个解决方法,详细了解答案.

html url get r httr

12
推荐指数
3
解决办法
3777
查看次数

使用tryCatch和rvest来处理404和其他爬行错误

使用时检索h1标题时rvest,我有时会遇到404页.这将停止该过程并返回此错误.

open.connection(x,"rb")出错:HTTP错误404.

请参阅下面的示例

Data<-data.frame(Pages=c(
"http://boingboing.net/2016/06/16/spam-king-sanford-wallace.html",
"http://boingboing.net/2016/06/16/omg-the-japanese-trump-commer.html",
"http://boingboing.net/2016/06/16/omar-mateen-posted-to-facebook.html",
"http://boingboing.net/2016/06/16/omar-mateen-posted-to-facdddebook.html"))
Run Code Online (Sandbox Code Playgroud)

用于检索h1的代码

library (rvest)
sapply(Data$Pages, function(url){
 url %>%
 as.character() %>% 
 read_html() %>% 
 html_nodes('h1') %>% 
 html_text()
 })
Run Code Online (Sandbox Code Playgroud)

有没有办法包含一个参数来忽略错误并继续这个过程?

r try-catch rvest

8
推荐指数
1
解决办法
9017
查看次数

标签 统计

r ×3

get ×1

html ×1

httr ×1

installation ×1

rvest ×1

try-catch ×1

ubuntu ×1

url ×1

xml ×1