RCurl 包中 getURL() 命令的 ViralHeat API 问题 [英] ViralHeat API issues with getURL() command in RCurl package

查看:30
本文介绍了RCurl 包中 getURL() 命令的 ViralHeat API 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 编程的病毒式 Heat API 来寻找我不是在开玩笑"的情绪(例如).我在 RCurl 包中使用了 getURL,如下所示:

I am trying to find the sentiment of "I am not joking" (For Example) using viral Heat API using R programming. I used getURL in RCurl package as shown below:

getURL("https://www.viralheat.com/api/sentiment/review.json?text=i%20am%20happy&api_key=", ssl.verifypeer=FALSE)

getURL("https://www.viralheat.com/api/sentiment/review.json?text=i%20am%20happy&api_key=", ssl.verifypeer=FALSE)

这在 Google Chrome 中运行良好.但在 IE 中,它被重定向到https://www.viralheat.com/browsers"作为ViralHeat API 不支持 IE Ver<9.

This is working fine in Google Chrome. But in IE it is getting redirected to "https://www.viralheat.com/browsers" as the ViralHeat API is incapable of IE Ver<9.

我将 R_BROWSER env 选项更改为 Google Chrome(这是我的默认浏览器).但是 getURL 仍然使用 IE,因为在执行上述 getURL 命令时仍然重定向到浏览器页面.我将 IE 版本升级到 11.但看起来像virusheatAPI 根本无法在 IE 上运行,因为它仍然被重定向到浏览器页面.

I changed the R_BROWSER env option to Google Chrome (which is my default browser). But getURL still uses IE as on execution of the above getURL command still redirects to browsers page. I upgraded the IE version to 11. But looks like viralheatAPI doesn't work on IE at all as it still getting redirected to browsers page.

有人遇到过这个问题吗?

Anybody faced this issue?

推荐答案

RCurl 提出的请求不使用您的浏览器.他们应该使用 RCurl 自己的库来发出 HTTP 请求.

Requests made by RCurl do not use your browser. They should use RCurl's own library for making HTTP requests.

该网站很可能会检查请求的用户代理字符串以查看它是否是有效的浏览器.RCurl 似乎不像浏览器那样默认指定用户代理字符串.如果您想模拟 Chrome,请转到 http://www.whatsmyuseragent.com/ 以查看您当前的用户代理字符串是.将该值复制到 R 中的变量,然后运行

Most likely the website checks the useragent string of the request to see it something is a valid browser. RCurl does not seem to specify a useragent string by default like your browser does. If you want to impersonate Chrome, go to http://www.whatsmyuseragent.com/ to see what your current useragent string is. Copy that value to a variable in R, then run

ua <- "<your full user agent here>"
getURL("https://www.viralheat.com/api/sentiment/review.json?text=i%20am%20happy&api_key=", 
    ssl.verifypeer=FALSE, .opts=list(useragent=ua))

这应该避免浏览器嗅探步骤,至少可以让您访问 API.

and that should avoid the browser sniffing step to at least get you to the API.

这篇关于RCurl 包中 getURL() 命令的 ViralHeat API 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆