|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 peter199083 于 2023-4-23 15:58 编辑
我在学习网抓,在克服网页用户名和密码登录的问题。
我利用Fiddler找到了使用浏览器登录网页时的一条记录,从Request Headers里面原封不动的拷贝复制Body内容(详见如下代码,其中用户名和密码做了隐藏)。由于字符串太长,我使用了空格+下划线的换行字符。
但是VBE依然在消息框提示”编译错误:语法错误“。有资深版友可以给一些提示么?提前谢谢了。
- Sub BasicPOSTRequestMultipleValues()
- Dim req As New MSXML2.XMLHTTP60
- Dim reqURL As String
- Dim reqBody As String
-
- reqURL = "https://XXXX.aspx"
-
- req.Open "POST", reqURL, False
-
- req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
-
- reqBody ="__LASTFOCUS=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKLTU5MjAzODM5MQ9kFgJmD2QWAgIBD2QWBAIBD2QWAgIFD2QWAmYPZBYCAgEPFgIeBFRleHQFB1NpZ24gSW5kAgMPZBYKAgMPFgIeB1Zpc2libGVoZAIFDxYCHwFoZAIJD2QWAgIBDxYCHwAFB1NpZ24gSW5kAgsPZBYEAgEPFgIfAAW8AVdhcm5pbmc6IHRoaXMgcGFnZSBpcyBub3QgZW5jcnl _
- wdGVkIGZvciBzZWN1cmUgY29tbXVuaWNhdGlvbi4gVXNlciBuYW1lcywgcGFzc3dvcmRzLCBhbmQgYW55IG90aGVyIGluZm9ybWF0aW9uIHdpbGwgYmUgc2VudCBpbiBjbGVhciB0ZXh0LiBGb3IgbW9yZSBpbmZvcm1hdGlvbiwgY29udGFjdCB5b3VyIGFkbWluaXN0cmF0b3IuZAIDD2QWAmYPZBYCAg0PEA8WAh4HQ2hlY2tlZGhkZGRk _
- Ag0PFgIfAWgWAgIBDw8WAh4ISW1hZ2VVcmwFIS9fbGF5b3V0cy8xMDMzL2l _
- tYWdlcy9jYWxwcmV2LnBuZ2RkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBS5jdGwwMCRQbGFjZUhvbGRlck1haW4kc2lnbkluQ29udHJvbCRSZW1lbWJlck1lkW8n5KdzWebP3B54AAJbGtvB1B8 _
- %3D&__VIEWSTATEGENERATOR=2EB18009&__EVENTVALIDATION=%2FwEWBQKr%2FJePDAKepvWvAQLp4fSGCQKHhvXBDQLsrazDCCz6GuST49bGSdmsrxU8XZZ0s7YG&ctl00%24 _
- PlaceHolderMain%24signInControl%24UserName=XXXX&ctl00%24PlaceHolderMain%24signInControl%24password=XXXX&ctl00%24PlaceHolderMain%24signInControl%24login=Sign+In"
-
- req.Send reqBody
-
- If req.Status <> 200 Then
- MsgBox req.Status & " - " & req.statusText
- Exit Sub
- End If
复制代码
|
|