简体   繁体   English

下载图片/ png - RCurl

[英]Download image/png - RCurl

I'm trying to use Clearbit.com's free logo API ( https://logo.clearbit.com/:domain ) to download the a few company logos. 我正在尝试使用Clearbit.com的免费徽标API( https://logo.clearbit.com/:domain )来下载一些公司徽标。

To try out the tool, simply paste https://logo.clearbit.com/nike.com into your web browser. 要试用该工具,只需将https://logo.clearbit.com/nike.com粘贴到您的网络浏览器中即可。

The goal is to save the Response from a GET request as a PNG file. 目标是将来自GET请求的响应保存为PNG文件。 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. 我搜索了文档,但我无法解决这个问题,所以请指教。

PS This is my first post on stackoverflow, so feel free to pose suggestions on style and general guidelines. PS这是我关于stackoverflow的第一篇文章,所以请随意提出关于样式和一般准则的建议。

Thanks, Ryan 谢谢,瑞恩

An alternative to RCurl is the new curl package of Jeroen Ooms, which provides a modern interface to libcurl . RCurl的替代是Jeroen Ooms的新卷曲包,它为libcurl提供了一个现代化的界面。

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

This is the image I downloaded: 这是我下载的图片:

在此输入图像描述

Try this 尝试这个

library(RCurl)
url <- "https://logo.clearbit.com/basf.com"
png <- getBinaryURL(url, httpheader = "image/png", ssl.verifypeer = F) # download
writeBin(png, con = tf <- tempfile(fileext = ".png")) # save
shell.exec(tf) # open file on windows

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

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