https://youtu.be/1wgSxzwUSIQ
webScrappingSendKeys
Código: Selecionar todos
Sub WebScrappingIE()
With Application
.SendKeys "^{ESC}"
.Wait Now + TimeValue("00:00:01")
.SendKeys "Executar"
.SendKeys "~"
.Wait Now + TimeValue("00:00:01")
.SendKeys "iexplore -nosessionmerging http://www2.correios.com.br/sistemas/precosPrazos/#ancora"
.SendKeys "~"
.Wait Now + TimeValue("00:00:05")
.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}"
'Data da postagem:
.SendKeys Format(DateAdd("d", 1, Now), "dd/MM/yyyy")
.SendKeys "{TAB}{TAB}"
'CEP de origem
.SendKeys "01310-200" 'MASP - S„o Paulo
.SendKeys "{TAB}{TAB}"
'CEP de destino
.SendKeys "20021-200" 'Museu Nacional do Rio de Janeiro
.SendKeys "{TAB}{TAB}"
'Tipo de serviÁo
.SendKeys "PAC"
.SendKeys "{TAB}{TAB}"
'Embalagem
.SendKeys "Embalagem"
.SendKeys "{TAB}{TAB}"
'Seleciona a caixa de encomenda
.SendKeys " "
.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}"
'Peso estimado
.SendKeys "1"
.SendKeys "{TAB}{TAB}{TAB}{TAB}"
.SendKeys "10000"
.SendKeys "{TAB}"
.SendKeys "~" 'Enviar consulta
.Wait Now + TimeValue("00:00:01")
'.SendKeys "~"
'.Wait Now + TimeValue("00:00:01")
'.SendKeys "~"
'Espera por uma nova p·gina
.Wait Now + TimeValue("00:00:03")
'navega atÈ a URL
.SendKeys "{TAB}" 'vai para a barra de endereÁos
.Wait Now + TimeValue("00:00:01")
'javascript:document.write(document.getElementsByClassName('content')[1].outerHTML);
.SendKeys "javascript+(;)document.write+(9)document.getElementsByClassName+(9)' content' +(0){[}1{]}.outerHTML+(0);"
.SendKeys "~"
.Wait Now + TimeValue("00:00:01")
.SendKeys "^(a)" 'Seleciona tudo
.Wait Now + TimeValue("00:00:01")
.SendKeys "^(c)" 'Ctrl+C
'coloca no resultado em uma nova planilha
Dim novaPlanilha As Worksheet
Set novaPlanilha = ThisWorkbook.Worksheets.Add
novaPlanilha.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False
'fecha o navegador
.SendKeys "%{F4}"
End With
End Sub
Sub Teste()
With Application
.SendKeys "^{ESC}"
.Wait Now + TimeValue("00:00:01")
.SendKeys "Executar"
.SendKeys "~"
.Wait Now + TimeValue("00:00:01")
.SendKeys "notepad"
.SendKeys "~"
.Wait Now + TimeValue("00:00:01")
.SendKeys "+(9)ol· notepad!' "
'.SendKeys "javascript+(;)document.write+(9)document.getElementsByClassName+(9)' content' +(0){[}1{]}.outerHTML+(0);"
End With
End Sub
modSelenium
Código: Selecionar todos
Dim driver As WebDriver
Sub ColetaDadosCorreios()
Set driver = New ChromeDriver
With driver
.Get "http://www2.correios.com.br/sistemas/precosPrazos/"
.FindElementById("data").SendKeys Format(DateAdd("d", 1, Now), "dd/MM/yyyy")
.FindElementByName("cepOrigem").SendKeys "01310-200" 'MASP - S„o Paulo
.FindElementByName("cepDestino").SendKeys "20021-200" 'Museu Nacional do Rio de Janeiro
.FindElementByName("servico").AsSelect().SelectByText ("PAC")
.FindElementByXPath("//*[@id=""spanFormato""]/img[1]").Click
.FindElementByName("embalagem1").AsSelect().SelectByValue ("correiosEmbalagem1")
.FindElementByXPath("//*[@id=""spanTipoEmbalagem""]/div/div[2]/div/div[1]/div/p/button").Click
.FindElementByName("peso").AsSelect().SelectByValue ("1")
.FindElementByName("valorDeclarado").SendKeys "10000"
.FindElementByXPath("//*[@id=""spanBotao""]/input").Click
.SwitchToNextWindow (1000)
Dim novaPlanilha As Worksheet
Set novaPlanilha = ThisWorkbook.Worksheets.Add
.FindElementByXPath("/html/body/div[1]/div[3]/div[2]/div/div/div[2]/div[2]/div[2]/table").AsTable().ToExcel (novaPlanilha.Cells(1, 1))
driver.Quit
End With
End Sub