其他分享
首页 > 其他分享> > 【四二学堂】基于UiBot实现的RPA项目-携程机器人订票

【四二学堂】基于UiBot实现的RPA项目-携程机器人订票

作者:互联网

流程:

流程一:

Dim dTime2=""
Dim dTime = ""
Dim sRet = ""
Dim hWeb = ""
Dim iRet = ""

// Dim sRet2=""
Dim arrayData = ""
Dim objExcelWorkBook = ""
Dim url=""

hWeb = WebBrowser.Create("chrome","https://www.ctrip.com/",30000,{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200,"sBrowserPath":"","sStartArgs":""})
#icon("@res:pt349gt6-s7kk-dnl1-h1p7-lv6ln5tefdhc.png")
Mouse.Action({"wnd":[{"cls":"Chrome_WidgetWin_1","title":"*","app":"chrome"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}],"html":[{"tag":"B","parentid":"searchBoxUl","idx":1}]},"left","click",10000,{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200,"bSetForeground":True,"sCursorPosition":"Center","iCursorOffsetX":0,"iCursorOffsetY":0,"sKeyModifiers":[],"sSimulate":"simulate","bMoveSmoothly":False})
#icon("@res:mdqkuai3-h87v-flof-v9hu-317adfv936b1.png")
UiElement.SetValue({"wnd":[{"cls":"Chrome_WidgetWin_1","title":"*","app":"chrome"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}],"html":[{"tag":"INPUT","id":"FD_StartCity"}]},"长沙",{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200})
#icon("@res:s74h57dh-206v-kekd-ageg-5gkav6040o84.png")
UiElement.SetValue({"wnd":[{"cls":"Chrome_WidgetWin_1","title":"*","app":"chrome"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}],"html":[{"tag":"INPUT","id":"FD_DestCity"}]},"北京",{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200})
dTime = Time.Date()
dTime2 = dTime+1
sRet = Time.Format(dTime2,"yyyy-mm-dd")
#icon("@res:ji36dfjq-55hk-5s1s-6ieq-q3hvanf4al7m.png")
UiElement.SetValue({"wnd":[{"cls":"Chrome_WidgetWin_1","title":"*","app":"chrome"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}],"html":[{"tag":"INPUT","id":"FD_StartDate"}]},sRet,{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200})
#icon("@res:default.png")
url="https://flights.ctrip.com/itinerary/oneway/CSX-BJS?date="&sRet  

iRet = WebBrowser.GoURL(hWeb,url,True,{"wnd":[{"cls":"Chrome_WidgetWin_1","title":"*","app":"chrome"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}],"html":[{"tag":"DIV","parentid":"app"}]},30000,{"bContinueOnError":False,"iDelayAfter":300,"iDelayBefore":200})
arrayData = UiElement.DataScrap({"html":[{"id":"base_bd","tag":"DIV"}],"wnd":[{"app":"chrome","cls":"Chrome_WidgetWin_1","title":"*"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},{"Columns":[{"props":["text"],"selecors":[{"className":"base_main","index":0,"prefix":"","tag":"div","value":"div.base_main"},{"className":"searchresult_content","index":0,"prefix":">","tag":"div","value":"div.searchresult_content"},{"className":"cabinV2","index":0,"prefix":">","tag":"div","value":"div.cabinV2"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"},{"className":"","index":2,"prefix":">","tag":"div","value":"div:nth-child(2)"},{"className":"","index":1,"prefix":">","tag":"div","value":"div:nth-child(1)"},{"index":0,"prefix":">","tag":"div","value":"div"},{"className":"flight_card_content","index":0,"prefix":">","tag":"div","value":"div.flight_card_content"},{"className":"search_table_header","index":0,"prefix":">","tag":"div","value":"div.search_table_header"},{"className":"inb logo","index":0,"prefix":">","tag":"div","value":"div.inb.logo"},{"className":"logo-item flight_logo","index":0,"prefix":">","tag":"div","value":"div.logo-item.flight_logo"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"}]},{"props":["text"],"selecors":[{"className":"base_main","index":0,"prefix":"","tag":"div","value":"div.base_main"},{"className":"searchresult_content","index":0,"prefix":">","tag":"div","value":"div.searchresult_content"},{"className":"cabinV2","index":0,"prefix":">","tag":"div","value":"div.cabinV2"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"},{"className":"","index":2,"prefix":">","tag":"div","value":"div:nth-child(2)"},{"className":"","index":1,"prefix":">","tag":"div","value":"div:nth-child(1)"},{"index":0,"prefix":">","tag":"div","value":"div"},{"className":"flight_card_content","index":0,"prefix":">","tag":"div","value":"div.flight_card_content"},{"className":"search_table_header","index":0,"prefix":">","tag":"div","value":"div.search_table_header"},{"className":"inb right","index":0,"prefix":">","tag":"div","value":"div.inb.right"},{"className":"time_box","index":0,"prefix":">","tag":"div","value":"div.time_box"},{"className":"time","index":0,"prefix":">","tag":"strong","value":"strong.time"}]},{"props":["text"],"selecors":[{"className":"base_main","index":0,"prefix":"","tag":"div","value":"div.base_main"},{"className":"searchresult_content","index":0,"prefix":">","tag":"div","value":"div.searchresult_content"},{"className":"cabinV2","index":0,"prefix":">","tag":"div","value":"div.cabinV2"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"},{"className":"","index":2,"prefix":">","tag":"div","value":"div:nth-child(2)"},{"className":"","index":1,"prefix":">","tag":"div","value":"div:nth-child(1)"},{"index":0,"prefix":">","tag":"div","value":"div"},{"className":"flight_card_content","index":0,"prefix":">","tag":"div","value":"div.flight_card_content"},{"className":"search_table_header","index":0,"prefix":">","tag":"div","value":"div.search_table_header"},{"className":"inb left","index":0,"prefix":">","tag":"div","value":"div.inb.left"},{"className":"time_box","index":0,"prefix":">","tag":"div","value":"div.time_box"},{"className":"time","index":0,"prefix":">","tag":"strong","value":"strong.time"}]},{"props":["text"],"selecors":[{"className":"base_main","index":0,"prefix":"","tag":"div","value":"div.base_main"},{"className":"searchresult_content","index":0,"prefix":">","tag":"div","value":"div.searchresult_content"},{"className":"cabinV2","index":0,"prefix":">","tag":"div","value":"div.cabinV2"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"},{"className":"","index":2,"prefix":">","tag":"div","value":"div:nth-child(2)"},{"className":"","index":1,"prefix":">","tag":"div","value":"div:nth-child(1)"},{"index":0,"prefix":">","tag":"div","value":"div"},{"className":"flight_card_content","index":0,"prefix":">","tag":"div","value":"div.flight_card_content"},{"className":"search_table_header","index":0,"prefix":">","tag":"div","value":"div.search_table_header"},{"index":0,"prefix":">","tag":"div","value":"div"},{"className":"","index":0,"prefix":">","tag":"div","value":"div"},{"className":"base_price02","index":0,"prefix":">","tag":"span","value":"span.base_price02"}]}],"ExtractTable":0},{"objNextLinkElement":"","iMaxNumberOfPage":5,"iMaxNumberOfResult":-1,"iDelayBetweenMS":1000,"bContinueOnError":False})

objExcelWorkBook = Excel.OpenExcel(@res"数据抓取.xlsx",True,"WPS","","")
Excel.WriteRange(objExcelWorkBook,"Sheet1","A1",arrayData,False)
Excel.Save(objExcelWorkBook)
Excel.CloseExcel(objExcelWorkBook,True)

Return arrayData


流程二:

Dim aa = []
Dim a1=''
Dim bb = []
Dim objExcelWorkBook = ""

// Dim cc=[]
Dim sRet = ""
// Dim dd=[]
Dim ee=0
Dim ff=''
Dim gg=''
Dim g1=''
Dim g2=''
Dim g3=''
Dim g4=''
Dim g5=''
Dim g6=''
Dim g7=''
Dim h=''
Dim h1=''
// Dim h2=''

aa = self.Input
a1=Len(aa)

For i = 0 To a1-1  Step 1 
	bb[i]=i+1
Next

objExcelWorkBook = Excel.OpenExcel(@res"数据抓取.xlsx",True,"WPS","","")

Excel.InsertColumn(objExcelWorkBook,"Sheet1","A1",bb,False)
Excel.InsertRow(objExcelWorkBook,"Sheet1","A1",['序号','航班号','出发时间','到达时间','价格'],False)

// 取得输入的值

Do While ee=0
	
	sRet = Dialog.InputBox("输入订第几张票","注意数字范围","",False)
	//判断是否输入了正确的编号
	
	h2=CInt(sRet)
	For Each value In bb
		If value=h2
			ee=value
			Break 
		Else
			Continue
		End If
	Next
Loop

ff=CInt(sRet)+1 //获得单元格的位置

h1=CStr(ff)
h="B" & h1 & ":" & "E" & h1

// TracePrint h
arrayRet = Excel.ReadRange(objExcelWorkBook,"Sheet1",h)
// TracePrint arrayRet
// 处理时间转换

g7=arrayRet[0][3]

g5=arrayRet[0][1]*24

g6=CStr(g5)
arrRet = Split(g6,".")
g1=arrRet[0]
g2=Left(CStr(arrRet[1]),13)
g2=CInt(g2)
g2=CStr(g2*60)
g2= Left(g2,2)

g5=arrayRet[0][2]*24

g6=CStr(g5)
arrRet = Split(g6,".")
g3=arrRet[0]

g4=Left(CStr(arrRet[1]),13)
g4=CInt(g4)
g4=CStr(g4*60)
g4= Left(g4,2)


gg="您的航班是:"&arrayRet[0][0]&";您出发的时间是:"&g1&"点"&g2&"分"&";您到达的时间是:"&g3&"点"&g4&"分"&";票的价格是:"&g7
Dialog.MsgBox(gg,"UiBot","0","1",0)

 

标签:index,value,RPA,className,prefix,tag,div,UiBot,四二
来源: https://blog.csdn.net/weixin_39593940/article/details/110304412