1
我的代碼中有什麼問題?我不知道如何結合結果。 這段代碼是ups交付數據,搜索運單很麻煩,所以我試了一下!但是很難。R重複代碼,抓取結果
這是代碼,
library(stringr)
Houseno <- c("1Z30A2920429127213","1Z30A2920429463047","1Z30A2920422913297","1Z30A2920439995052","1Z30A2920423741926")
Houseno
for (i in Houseno)
{
url <- (paste0("https://iship.com/trackit/track.aspx?Track=",i))
line <- readLines(url, encoding = "UTF-8")
#number
upshouse <- line[which(str_detect(line,"UPS Tracking Number:"))]
upshouse <- gsub("UPS Tracking Number:|<.+?>|\t| ", "", upshouse)
#result
upsresult <- line[which(str_detect(line,"Status:"))]
upsresult <- gsub("Status:|<.+?>|\t", "", upsresult)
#com
com <- data.frame(NO=upshouse, CP=upsresult)
print(com)
}
這段代碼的結果是
NO CP
1 1Z30A2920429127213 DELIVERED
NO CP
1 1Z30A2920429463047 DELIVERED
NO CP
1 1Z30A2920422913297 DELIVERED
NO CP
1 1Z30A2920439995052 DELIVERED
NO CP
1 1Z30A2920423741926 DELIVERED
但我想這個結果是如下,
NO CP
1 1Z30A2920429127213 DELIVERED
2 1Z30A2920429463047 DELIVERED
3 1Z30A2920422913297 DELIVERED
4 1Z30A2920439995052 DELIVERED
5 1Z30A2920423741926 DELIVERED
謝謝。
噢,我的天啊..謝謝天才! –