R 中的 URL 语义分析



我有一个包含各种网址的数据集。

https://www.thetrainline.com/buytickets/combinedmatrix.aspx?Command=TimeTable
https://wwf-fb.zyngawithfriends.com/wwf-fb.a84485c126e67ea2787c.html
http://www.thetrainline.com/destinations/trains-to-london

我想对 url(URL 中的关键字在/之后)进行语义分析。

请帮帮我。

谢谢

这比您手动执行此操作要快得多,也更全面。

library(urltools)
URLs <- c("https://www.thetrainline.com/buytickets/combinedmatrix.aspx?Command=TimeTable",
          "https://wwf-fb.zyngawithfriends.com/wwf-fb.a84485c126e67ea2787c.html",
          "https:/test.com/thing.php?a=1&b=2",
          "http://www.thetrainline.com/destinations/trains-to-london")
url_parse(URLs)
##   scheme                      domain port                             path         parameter fragment
## 1  https        www.thetrainline.com        buytickets/combinedmatrix.aspx command=timetable         
## 2  https wwf-fb.zyngawithfriends.com      wwf-fb.a84485c126e67ea2787c.html                           
## 3                              https                    test.com/thing.php           a=1&b=2         
## 4   http        www.thetrainline.com         destinations/trains-to-london   
URLs1 <- c('http://www.thetrainline.com/destinations/trains-to-london', 'https://wwf-fb.zyngawithfriends.com/wwf-fb.a84485c126e67ea2787c.html', 'https://www.thetrainline.com/buytickets/combinedmatrix.aspx?Command=TimeTable')
> gsub('^(?:[^/]*/){3}','/', URLs1)
[1] "/destinations/trains-to-london"                    "/wwf-fb.a84485c126e67ea2787c.html"                
[3] "/buytickets/combinedmatrix.aspx?Command=TimeTable"
> 

最新更新