第一次提问,请耐心等待。
我的问题类似于这个问题:Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA
但是对于我的项目,我需要登录amazon.com(" https://www.amazon.com/sign-in")并将其(部分)作为vbs文件。
我的主要问题似乎是正确构建查询数据(" Postdata")。任何帮助都会受到高度赞赏!
编辑:所以我到目前为止所做的工作以及遇到麻烦的地方。
此脚本应该让我从amazon.com下载个人信息
function download(sFileURL, sLocation, async)
set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", sFileURL, async
on error resume next
objXMLHTTP.send()
if err.number = 0 then
do until objXMLHTTP.Status = 200
wscript.echo objXMLHTTP.Status
wcript.sleep(200)
loop
if objXMLHTTP.Status = 200 Then
set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0
set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation
Set objFSO = Nothing
objADOStream.SaveToFile sLocation
objADOStream.Close
set objADOStream = Nothing
download = true
end if
else
download = false
end if
set objXMLHTTP = Nothing
end function
if download("https://www.amazon.com/gp/primecentral?ref_=ya_d_c_prime","C:\Test\test.html",false) then WScript.Echo "Finished!"
“守则”似乎有效,但我只是下载“#34;登录"页。
我已添加此脚本,可让我登录亚马逊,但不会改变问题
Const HomeUrl = "https://www.amazon.com/sign-in"
Function IE_Start()
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
End Function
Sub IE_WaitLoading(ie)
Do While ie.Busy Or ie.readystate <> 4
WScript.Sleep 500
Loop
End Sub
Sub IE_OpenUrlAndWait(ie, url)
ie.Navigate url
IE_WaitLoading ie
End Sub
Dim ie
Set ie = IE_Start()
IE_OpenUrlAndWait ie, HomeUrl
ie.Document.getElementById("ap_email").Value = "Username"
ie.Document.getElementById("ap_password").Value = "PWD"
ie.Document.getElementById("signInSubmit").Click()
所以解决方案似乎是这里显示的脚本:Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA
然而,遗憾的是,我完全不知道如何构建Postdata变量的正确查询。 任何帮助将非常感谢!