Skip to content

Instantly share code, notes, and snippets.

@wmcraver
Created January 19, 2017 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmcraver/6ef9ce3a76aaefe2c507e92deab82a47 to your computer and use it in GitHub Desktop.
Save wmcraver/6ef9ce3a76aaefe2c507e92deab82a47 to your computer and use it in GitHub Desktop.
A quick script I use to extract key items from URLs. This makes quick work for double checking the structure of SEO/SEM URLs.
library(urltools)
# Read in the URLs
dat = read.csv("LandingPageURLs.csv", stringsAsFactors = F)
# Extract the scheme, domain, and path from the urls
dat$scheme = scheme(dat$LandingPage)
dat$domain = domain(dat$LandingPage)
dat$path = path(dat$LandingPage)
# Extract particular parameters from the URLs
x = param_get(dat$LandingPage, c("parameter1", "parameter2", "parameter3", "etc"))
#combine the original data set and the extracted parameters data set together into a new data frame
datNew = cbind(dat, x)
# Write the data frame to CSV
write.csv(datNew, "URL-Split.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment