What is my user agent when analyzing a website with the rvest package in R?

Since this is easy in R, I use the rvest HTML parsing package to extract information from a website.

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

My code that opens a session and extracts information 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" ) 
+4
source share
2 answers

I used https://httpbin.org/user-agent to find out:

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

Answer:

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

See this bug report for overriding it.

+7
source

I found this somewhere in a tutorial, it looks like a faster way to do this:

 uastring <- "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" session <- html_session("https://www.linkedin.com/job/", user_agent(uastring)) 
+3
source

Source: https://habr.com/ru/post/1011608/


All Articles