1

I am fairly new to R, and have never used it for writing a web query before. I was wondering if there were any preexisting packages out there that would fit my needs. I am trying to search for a company and return the URL of their website. I have the company name, address, and phone number. Is there a way to run a program that will check the website against the information I have to confirm it's the correct website?

2
  • Have a look at RCurl, that could be a good option for you. Commented May 6, 2013 at 20:01
  • 1
    And httr: github.com/hadley/httr. It provides a more user friendly wrapper on top of RCurl. Commented May 7, 2013 at 12:42

2 Answers 2

5

Can't guarantee that this will work every time but definitely use the RCurl package

library(RCurl)
geturlname <- function(name){
    h = getCurlHandle()
    z <- getURL(paste0("http://google.com/search?btnI=1&q=",name), # google i'm feeling lucky
        followlocation=TRUE, curl=h)
    getCurlInfo(h)$effective.url # catch the url redirect
}
geturlname("Apple")
geturlname("Google")
geturlname("Blockbuster")
Sign up to request clarification or add additional context in comments.

Comments

4

Thomas' function is a little easier to write with httr because it:

  • automatically manages handles for you

  • automatically follows redirects

  • returns an object that represents the results of the request

And here's the function:

library(httr)
geturlname <- function(name){
  url <- paste0("http://google.com/search?btnI=1&q=", name)
  GET(url)$url
}
geturlname("Apple")
geturlname("Google")
geturlname("Blockbuster")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.