[分享] 更進一步使用RSelenium抓取PTT內容與通知消失

看板R_Language作者時間7年前 (2016/07/24 01:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
最近看到有人教學使用RSelenium 抓取PTT的內容https://www.youtube.com/watch?v=PYy5C9IIgp8
我自學了一下發現的確可行我自己本身因為有搭共乘的需求特別搭乘的是比較少人提供的部分所以我想更進一步使用這個方法並且進一步通知上述網址的教學只能將爬到的檔案存成一個file並且限制在該網頁的首頁但是我希望更多的功能為以下,想要請問一下不知道可否使用R更進一步處理1. 爬取更多頁面或是該版所有的頁面這個部分我發現他似乎根據網址的index那邊變動如果我使用最舊就會等於1,下一頁就是二但我使用最新他只會顯示indexhttps://www.ptt.cc/bbs/car-pool/index2.html似乎可以寫回圈去提取2. 定期自動爬蟲我想要讓電腦設定每兩小時爬一次,不知道要怎樣設定不知道是否可以教學一下謝謝以下是使用他的教學我產生的codelibrary(RSelenium)url= "https://www.ptt.cc/bbs/car-pool/index.html"remDr <- remoteDriver(remoteServerAddr = "localhost" , port = 4444 , browserName ="firefox")remDr$open() #open browserremDr$getStatus()#check the status of browserremDr$navigate(url)# website to crawl#the separate symbol in ppt is r-ent#get the element from the websitewebElem<-remDr$findElements('css selector', ".r-ent")#class for period (.) idthen use #a = sapply(webElem, function(x){ c =x$findChildElement('css selector', '.author') d =x$findChildElement('css selector', '.title') e =x$findChildElement('css selector', '.date') cbind(c("author" = c$getElementText(), "title" =d$getElementText(),e$getElementText())) })t=as.data.frame(t(a))--※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.214.99※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1469296338.A.F43.html※ 編輯: wanson (140.112.214.99), 07/24/2016 03:28:09
文章代碼(AID): #1NawxIz3 (R_Language)
文章代碼(AID): #1NawxIz3 (R_Language)