Let's say I have a series of URL strings that I've imported into R.
url = c("http://www.mdd.com/food/pizza/index.html", "http://www.mdd.com/build-your-own/index.html",
"http://www.mdd.com/special-deals.html", "http://www.mdd.com/find-a-location.html")
I want to parse through these url's to identify what page they are. I want to be able to map url[3] to special deals page. For this example, let's say I have the following 'types' of pages.
xtype = c("deals","find")
dtype = c("ingrediants","calories","chef")
Given these types, I want to take the url variable and map them together.
So I should end up with:
> df
url site
1 http://www.mdd.com/food/pizza/index.html dtype
2 http://www.mdd.com/build-your-own/index.html dtype
3 http://www.mdd.com/special-deals.html xtype
4 http://www.mdd.com/find-a-location.html xtype
I began looking into this project by thinking that I'd need to use strsplit to strip apart each url. However, the following doesn't work to split apart the url. Splitting apart the url's would allow me to put together some if-else statements for performing this task. Efficient? No, but as long as it get's the job done.
Words = strsplit(as.character(url), " ")[[1]]
Words
Here are my main questions:
1. Is there a package to do URL parsing in R?
2. How can I go about identifying the page which is viewed from a large url string?
EDIT:
What I'm asking is this: How can I figure out the 'specific page' from a url string. So if I have "http://www.mdd.com/build-your-own/index.html" I want to know how I can extract just build-your-own.
There's also the urltools
package now which is infinitely faster than most other methods:
url <- c("http://www.mdd.com/food/pizza/index.html",
"http://www.mdd.com/build-your-own/index.html",
"http://www.mdd.com/special-deals.html",
"http://www.mdd.com/find-a-location.html")
urltools::url_parse(url)
## scheme domain port path parameter fragment
## 1 http www.mdd.com food/pizza/index.html
## 2 http www.mdd.com build-your-own/index.html
## 3 http www.mdd.com special-deals.html
## 4 http www.mdd.com find-a-location.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With