当我用 R 中的 rvest 包解析网站时,我的用户代理是什么? [英] What's my user agent when I parse website with rvest package in R?

查看:39
本文介绍了当我用 R 中的 rvest 包解析网站时,我的用户代理是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在 R 中很容易,我使用 rvest 包来解析 HTML 以从网站中提取信息.

Since it is easy in R, I am using rvest package to parse HTML to extract informations from website.

我想知道在请求期间我的 User-Agent 是什么(如果有的话),因为 User-Agent 被分配给了互联网浏览器,或者有没有办法以某种方式设置它?

I am wondering what's my User-Agent (if there is any) during the request, since User-Agent is assigned to the internet browser or is there a way to set it somehow?

我打开会话并从 HTML 中提取信息的代码如下:

My code that open session and extract informations from HTML is below:

library(rvest)
se <- html_session( "http://www.wp.pl" ) %>% 
html_nodes("[data-st-area=Glonews-mozaika] li:nth-child(7) a") %>%
html_attr( name = "href" )

推荐答案

我使用了 https://httpbin.org/user-agent 找出:

library(rvest)
se <- html_session( "https://httpbin.org/user-agent" )
se$response$request$options$useragent

答案:

[1] "libcurl/7.37.1 r-curl/0.9.1 httr/1.0.0"

请参阅此错误报告以了解覆盖它的方法.

See this bug report for a way to override it.

这篇关于当我用 R 中的 rvest 包解析网站时,我的用户代理是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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