Download image/png - RCurl

时间:2015-06-30 19:24:32

标签: r http rcurl

I'm trying to use Clearbit.com's free logo API (https://logo.clearbit.com/:domain) to download the a few company logos.

To try out the tool, simply paste https://logo.clearbit.com/nike.com into your web browser.

The goal is to save the Response from a GET request as a PNG file. Here is a an example of the code I'm using, which fails.

    library(RCurl)
    url <- "https://logo.clearbit.com/basf.com"
    png <- getURL(url, httpheader = "image/png", ssl.verifypeer = F)

This produces the following error message:

    Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 
    embedded nul in string:'‰PNG\r\n\032\n\0\0\0\rIHDR\0\0\0\0\0\0\b\006\0\0\0Ã>aË\0\0\0\004gAMA\0\0±\vüa\005\0\0\0 cHRM\0\0z&\0\0€„\0\0ú\0\0\0€è\0\0u0\0\0ê`\0\0:˜\0\0\027pœºQ<\0\0\0\006bKGD\0ÿ\0ÿ\0ÿ ½§“\0\0\0\atIME\aß\006\036\022\0228_nn\005\0\0\027$IDATxÚíyx[Õ÷?÷^IW»dË–÷5v\026'qœ•¤$!%$¡P(]\030Z†y™2CK\aZ\006ž–ç-Ó…¶Ó>}g\nü¥lçi¡e:L\031\030(…°¦¤$$„fOììÞâ}·,YÒ]æ\017+"ŠäÄÄv3ɽŸ<y\022stîÑ9ß{öó;Â뇟Ô11,â…N€É…Å\024€Á1\005`pL\001\030\034S\0\006Ç\024€Á1\005`pL\001\030\034S\0\006Ç2•‘9­^<r\016ƒ£Œ*#IwQÈu•eüNgèxòÿ’hÁoÏG\024$B±>"ñá\v?—<S(\0êœË\bºËÙÛþ\026£§\025¬WΡ¶`mÆo½qd,œßžÇü‚µØ-®¤_W¨‘\003›Q´è…ΧK–I\vÀ#çà·ç‘ï©ÄïÈÏ\030ÆkÏ\005 y`?]¡¦4\177I´RW¸\036«dçP÷{Œ*#ÌÊ]NÐ]Žª)ìïÜt¡óé’eÒ\002(ò΢Ä_sÖ0.[\026\0ý‘\016ú#miþ9Î\022¬’þH;Í\003û\001\020\005‘ùùW’ç©à`×f4]M†\027\004‘ «\034€P¬‘Ø\00Ö„ä8K\023Ïj'¦FD+\005ž*|ö º®Ñ>|,-\r\016«—|Ï\f\\6?è:‘ø0¡ã„bý\0Ø-.|ö<¢Ê\b\021%D©\177. p¤g;N«—|O\025.›\017\035\030\036íáäÐዦ֚´\0:C'\bÇ\a\001(ñÏÅiõ¦…q'\004à°z¨+\\(XÆ\n»\177\037ª®$kˆS\031\0160\020é\004Æú\017n9›¡

I've searched through the documentation, but I have not been able to remedy this, so please advise.

P.S. This is my first post on stackoverflow, so feel free to pose suggestions on style and general guidelines.

Thanks, Ryan

2 个答案:

答案 0 :(得分:6)

RCurl 的替代方案是Jeroen Ooms的新 curl 包,它为libcurl提供了一个现代化的界面。

## install.packages("curl")
library("curl")
curl_download(url = "https://logo.clearbit.com/basf.com",
              destfile = "~/foo.png")

这是我下载的图片:

enter image description here

答案 1 :(得分:3)

试试这个

.stop(true, true)