Re: [問題] parsing的中文顯示
→
06/21 16:20,
06/21 16:20
→
06/21 16:21,
06/21 16:21
→
06/21 16:21,
06/21 16:21
→
06/21 16:21,
06/21 16:21
好讀版:http://pastebin.com/zNjkb0uh
csv結果:http://www.mediafire.com/download/a3d7aat94yhz16n/familyMart_loc.csv
我用查郵遞區號方式去對inquery.aspx查詢
這裡最重要的是用curl的referer
我一開始找不到httr的方法去設定,所以先用了RCurl去做
後面補上用httr的GET的做法
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)
partial results:
NAME TEL POSTel px py
1 全家新德店 02-23214351 02-77463163 121.5316 25.04447
2 全家台醫店 02-23278841 02-23279603 121.5185 25.04079
3 全家南機場店 02-23039420 02-77095865 121.5058 25.02840
4 全家新惠安店 02-23036887 02-77300717 121.5065 25.02953
5 全家新龍口店 02-23047184 02-77300715 121.5104 25.02723
6 全家新廈門店 02-23681443 02-77397215 121.5176 25.02532
--
R資料整理套件系列文:
magrittr #1LhSWhpH (R_Language) http://tinyurl.com/j3ql84c
data.table #1LhW7Tvj (R_Language) http://tinyurl.com/hr77hrn
dplyr(上) #1LhpJCfB (R_Language) http://tinyurl.com/jtg4hau
dplyr(下) #1Lhw8b-s (R_Language)
tidyr #1Liqls1R (R_Language) http://tinyurl.com/jq3o2g3
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.76.63.212
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1466514438.A.696.html
※ 編輯: celestialgod (211.76.63.212), 06/21/2016 21:19:40
推
06/22 15:51, , 1F
06/22 15:51, 1F
→
06/22 15:52, , 2F
06/22 15:52, 2F
→
06/22 15:52, , 3F
06/22 15:52, 3F
→
06/22 17:36, , 4F
06/22 17:36, 4F
→
06/22 17:47, , 5F
06/22 17:47, 5F
→
06/22 17:47, , 6F
06/22 17:47, 6F
推
06/23 09:10, , 7F
06/23 09:10, 7F
推
06/23 09:59, , 8F
06/23 09:59, 8F
→
06/23 10:00, , 9F
06/23 10:00, 9F
討論串 (同標題文章)
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章