rvest总结的非常全面的教程:https://blog.csdn.net/weixu22/article/details/79237512
仅用作练习模拟鼠标点击,确认,输入文字等操作,没有写完整,因为美团的登陆需要滑动方块验证,还不知道这个咋操作!
########################################################
#-------------------------------------------------------
# Topic:使用webdriver爬取美团拉面外卖信息
# Author:
# Date:Fri Feb 26 11:19:46 2021
# Mail:
#-------------------------------------------------------
########################################################
library(webdriver)
library(rvest)
js<-run_phantomjs()
js
session_ins<-Session$new(port = js$port)
session_ins$go("https://www.baidu.com")
session_ins$takeScreenshot()
baidu_input<-session_ins$findElement(xpath = '//input[@name="wd"]')
baidu_input$sendKeys("美团")
session_ins$takeScreenshot()
baidu_input_search<-session_ins$findElement(xpath = '//input[@id="su"]')
baidu_input_search$click()
session_ins$takeScreenshot()
meituan_guanwang<-session_ins$findElement(xpath = '//div[@id=1]/h3/a')
meituan_url<-meituan_guanwang$getAttribute(name = "href")
session_ins$go(meituan_url)
session_ins$takeScreenshot()
session_ins$getUrl()
meituan_search_box<-session_ins$findElement(xpath = '//input[@placeholder="搜索商家或地点"]')
meituan_search_box$sendKeys("拉面",key$enter)
session_ins$takeScreenshot()
网友评论