Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(httr)
- library(xml2)
- library(pipeR)
- library(purrr)
- library(stringi)
- library(stringr)
- library(RCurl)
- library(jsonlite)
- url_postCodes <- "http://www.easytravel.com.tw/postid_search.asp"
- all_postCodes <- url_postCodes %>>% GET %>>% content(encoding = "big5") %>>%
- xml_find_all("//td/font") %>>% xml_text %>>%
- stri_conv(from = "UTF-8", to = "Big5") %>>% str_extract("\\d{3}") %>>%
- `[`(!is.na(.)) %>>% as.integer
- # method with RCurl::getURL
- familyMartLoc <- lapply(all_postCodes, function(postCode){
- url_toPrint <- str_c("http://api.map.com.tw/net/GraphicsXY.aspx?",
- "search_class=Zip&Zip=%i&fun=getCityByZipReturn")
- city_area <- sprintf(url_toPrint, postCode) %>>%
- getURL(referer = "http://www.family.com.tw/marketing/inquiry.aspx") %>>%
- str_replace_all("getCityByZipReturn\\(|\\)", "") %>>% fromJSON
- url_toPrint <- str_c("http://api.map.com.tw/net/familyShop.aspx?",
- "searchType=ShopList&type=&city=%s&area=%s&road=&",
- "fun=showStoreList&key=6F30E8BF706D653965BDE302661D1241F8BE9EBC")
- sprintf(url_toPrint, city_area$COUNTY, city_area$TOWN) %>>%
- getURL(referer = "http://www.family.com.tw/marketing/inquiry.aspx") %>>%
- str_replace_all("showStoreList\\(|\\)", "") %>>% fromJSON
- }) %>>% do.call(what = rbind)
- # method with httr::GET
- familyMartLoc2 <- lapply(all_postCodes, function(postCode){
- url_toPrint <- str_c("http://api.map.com.tw/net/GraphicsXY.aspx?",
- "search_class=Zip&Zip=%i&fun=getCityByZipReturn")
- city_area <- sprintf(url_toPrint, postCode) %>>%
- GET(config(referer = "http://www.family.com.tw/marketing/inquiry.aspx")) %>>%
- content("text") %>>% str_replace_all("getCityByZipReturn\\(|\\)", "") %>>% fromJSON
- url_toPrint <- str_c("http://api.map.com.tw/net/familyShop.aspx?",
- "searchType=ShopList&type=&city=%s&area=%s&road=&",
- "fun=showStoreList&key=6F30E8BF706D653965BDE302661D1241F8BE9EBC")
- sprintf(url_toPrint, city_area$COUNTY, city_area$TOWN) %>>%
- GET(config(referer = "http://www.family.com.tw/marketing/inquiry.aspx")) %>>%
- content("text") %>>% str_replace_all("showStoreList\\(|\\)", "") %>>% fromJSON
- }) %>>% do.call(what = rbind)
Advertisement
Add Comment
Please, Sign In to add comment