2017-04-05 38 views
-2

我想模擬ie.document.getElementbyId("buttom_id").(0).clickXMLHTTPREQUEST在VBS中使用httprequest點擊buttom

因此在點擊按鈕:

  1. 右鍵點擊網頁,然後選擇 'Inspect' 時

  2. 選擇網絡選項卡

  3. 複製所有的HAR

這種互動如下: HAR FILE

我的代碼如下:

Function SaveGraphImageFromURLs(fileUrl, filePath) 

Dim FileNum As Long 
Dim FileData() As Byte 
Dim WHTTP As Object 

fileUrl = "http://80.191.214.122/Orion/Charts/CustomChartData.ashx?Calculate95thPercentile=True&CalculateTrendLine=True&ChartDateSpan=1&ChartInitialZoom=yesterday&ChartName=MMAvgBps&ChartSubTitle=%24%7bZoomRange%7d&ChartTitle=%24%7bCaption%7d&Height=0&NetObject=I%3a21067&ResourceID=69&SampleSize=30&Width=640&DataFormat=ChartData&NetObjectIds=21067" 

WHTTP.Open "post", fileUrl, False 
WHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
WHTTP.send 

FileData = WHTTP.responseBody 
Set WHTTP = Nothing 

'Save the file 
FileNum = FreeFile 

Open filePath For Binary Access Write As #FileNum 
Put #FileNum, 1, FileData 
Close #FileNum 
Debug.Print "File has been saved!", vbInformation, "Success" 
End Function 
+1

您發佈的代碼不是VBScript中解決問題:) 。另外,你的問題是什麼?有什麼不行嗎? –

+0

由於我沒有憑據,無法打開提供的URL。你最終想通過點擊按鈕來達到什麼目的?請將預期的輸出添加到問題中。我在HAR中看到的唯一相關數據是包含表格的第二個響應中的HTML網頁,請參閱[鏈接的截圖](https://i.stack.imgur.com/C8Y8F.png)。 – omegastripes

回答

0

終於我可以通過更換

Function SaveGraphImageFromURLs(fileUrl, filePath) 

Dim FileNum As Long 
Dim FileData() As Byte 
Dim WHTTP As Object 

fileUrl = "http://80.191.214.122/Orion/Charts/CustomChartData.ashx?Calculate95thPercentile=True&CalculateTrendLine=True&ChartDateSpan=1&ChartInitialZoom=yesterday&ChartName=MMAvgBps&ChartSubTitle=%24%7bZoomRange%7d&ChartTitle=%24%7bCaption%7d&Height=0&NetObject=I%3a21067&ResourceID=69&SampleSize=30&Width=640&DataFormat=ChartData&NetObjectIds=21067" 

displaydata = "DisplayDetails=eyJkYXRhVXJsIjoiL09yaW9uL0ludGVyZmFjZXMvU2VydmljZXMvSW50ZXJmYWNlQ2hhcnREYXRhLmFzbXgvTU1BdmdCcHMiLCJ0aXRsZSI6IkZhc3RFdGhlcm5ldDEvMC80OCA%2FICMjIyBVUExJTksgLSAoIExpbmstMiApIC0gQ09OTkVDVEVELVRPLU9SVU1JRUgtUEFZQU0tRklCRVJIT01FLTMiLCJzdWJ0aXRsZSI6IiRbWm9vbVJhbmdlXSIsInNob3dUaXRsZSI6dHJ1ZSwibmV0T2JqZWN0SWRzIjpbIjIxMDY3Il0sInNhbXBsZVNpemVJbk1pbnV0ZXMiOjMwLCJyZW5kZXJUbyI6ImN0bDAwX2N0bDAwX0JvZHlDb250ZW50X0NvbnRlbnRQbGFjZUhvbGRlcjFfY3RsODJfY3RsMDBfV3JhcHBlcl9jdGwwMSIsIkNhbGN1bGF0ZVRyZW5kTGluZSI6dHJ1ZSwiQ2FsY3VsYXRlU3VtIjpmYWxzZSwiQ2FsY3VsYXRlOTV0aFBlcmNlbnRpbGUiOnRydWUsImluaXRpYWxab29tIjoieWVzdGVyZGF5IiwiUmVzb3VyY2VQcm9wZXJ0aWVzIjp7ImNoYXJ0bmFtZSI6Ik1NQXZnQnBzIiwiY2hhcnRpbml0aWFsem9vbSI6Inllc3RlcmRheSIsIm5ldG9iamVjdHByZWZpeCI6IkkiLCJjaGFydHN1YnRpdGxlIjoiJHtab29tUmFuZ2V9IiwiY2FsY3VsYXRldHJlbmRsaW5lIjoiMSIsImNoYXJ0ZGF0ZXNwYW4iOiIxIiwic2hvd3RpdGxlIjoiMSIsInNhbXBsZXNpemUiOiIzMCIsImNhbGN1bGF0ZTk1dGhwZXJjZW50aWxlIjoiMSIsImNhbGN1bGF0ZXN1b" 
displaydata = displaydata & "SI6IjAiLCJjaGFydHRpdGxlIjoiJHtDYXB0aW9ufSJ9LCJ0aXRsZVdpZHRoIjo2NDAsInN1YlRpdGxlV2lkdGgiOjY0MCwiRGF0ZUZyb21VdGMiOiIwMDAxLTAxLTAxVDAwOjAwOjAwWiIsIkRhdGVUb1V0YyI6IjAwMDEtMDEtMDFUMDA6MDA6MDBaIiwidGltZXNwYW5JbkRheXMiOjEsImxlZ2VuZEluaXRpYWxpemVyIjoiY29yZV9zdGFuZGFyZExlZ2VuZEluaXRpYWxpemVyX19jdGwwMF9jdGwwMF9Cb2R5Q29udGVudF9Db250ZW50UGxhY2VIb2xkZXIxX2N0bDgyX2N0bDAwX1dyYXBwZXJfY3RsMDRfbGVnZW5kIiwiQ2hhcnRFZGl0VXJsIjoiL09yaW9uL0NoYXJ0cy9DdXN0b21DaGFydC5hc3B4P1Jlc291cmNlSUQ9NjlcdTAwMjZOZXRPYmplY3Q9SToyMTA2NyIsImxvYWRpbmdNb2RlIjowfQ%3D%3D" 

WHTTP.Open "post", fileUrl, False 
WHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
WHTTP.send displaydata 

FileData = WHTTP.responseBody 
Set WHTTP = Nothing 

'Save the file 
FileNum = FreeFile 

Open filePath For Binary Access Write As #FileNum 
Put #FileNum, 1, FileData 
Close #FileNum 
Debug.Print "File has been saved!", vbInformation, "Success" 
End Function