我是刮从网址http://iias.ac.in/recent-publications的网页数据。我已经刮了这个页面所有标题的数据使用'rvest‘。现在,我有了一个向量,它包含了书名为
titl_book 1“泰戈尔的一些散文:历史、社会、政治” 2“看不见的网:对Jangarh Singh Shyam生死存亡的艺术史探究”。
现在,我正在根据像这个http://iias.ac.in/publication/some-essays-tagore-history-society-politics这样的书的标题来抓取每一本书的数据,其中url就是其中的一个
由于向量titl_book包含普通url "http://iias.ac.in“的后缀,因此如何一次性抓取所有这些URL的数据。
发布于 2019-04-28 02:00:30
嗯,似乎需要一些数据清理步骤。我强烈推荐stringr包。我就是这样做的。
title_book = c("Some Essays of Tagore : History. Society. Politics",
"INVISIBLE WEBS: An art Historical inquiry into the life and death of Jangarh Singh Shyam")
title_book_edited = title_book %>%
str_to_lower() %>%
str_replace_all(pattern = " ", replacement = "-") %>%
str_remove_all(pattern = ":") %>%
str_remove_all(pattern = "\\.")
title_book_list = paste0("http://iias.ac.in/publication/", title_book_edited)我使用str_to_lower()转换字符串的大小写,用str_replace_all()替换所有匹配的模式,使用str_remove_all()删除所有匹配的模式。输出结果会是这样。
> title_book_list
[1] "http://iias.ac.in/publication/some-essays-of-tagore--history-society-politics"
[2] "http://iias.ac.in/publication/invisible-webs-an-art-historical-inquiry-into-the-life-and-death-of-jangarh-singh-shyam"有关更多信息,请访问这份正式文件。我希望你觉得这有帮助。
https://stackoverflow.com/questions/55886044
复制相似问题