小编pjp*_*rez的帖子

curl :: curl_fetch_memory(url,handle = handle)出错:从对等端接收数据失败

我正试图从图表API获取歌词.我编写了一个可以工作但不在循环内的R函数.我的脚本是:

library(httr)
library(RCurl)
library(XML)

df <- data.frame(artist = c('Led Zeppellin', 'Adele'), song = c('Rock´n roll', 'Hello'), stringsAsFactors = F)

make.querye <- function(xx) {
  names_ok <- gsub(" ", "&", xx)
  names_ok2 <- paste("\'", names_ok, "\'", sep = '')
 querye <- paste("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=", names_ok[1],"&song=",  names_ok[2], sep='')
 data <- GET(querye)
 aa <- content(data, "text")   
 doc <- htmlParse(aa, asText=TRUE)  
 plain.text <- xpathSApply(doc, "//lyric//text()[not(ancestor::script)][not(ancestor::style)][not(ancestor::noscript)][not(ancestor::form)]", xmlValue)  
 if (length(plain.text)==0) {
   plain.text2 <- 'Lyrics not found'
 } else {
   plain.text2 <- iconv(plain.text, from = "UTF-8", to = …
Run Code Online (Sandbox Code Playgroud)

loops r rcurl httr

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

标签 统计

httr ×1

loops ×1

r ×1

rcurl ×1