First time question so please bear with me.
My question is similar to this question: Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA
However for my project I'd need to login to amazon.com ("https://www.amazon.com/sign-in") and make this (part of) a vbs-file.
The main problem to me seems to be constructing the data for the query correctly ("Postdata"). Any help there would be highly appreciated!
EDIT: So here's what I've done so far and where I'm stuck in trouble.
This script should let me download personal information from 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!"
The Code seems to work, however I'm only downloading the "Sign-In" page.
I've added this script, which lets me log in to amazon, but it does not change the problem
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()
So the solution seems to be the script shown here: Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA
However I've unfortunately got absolutely no clue at all as how to construct the right query for the Postdata-variable. Any help would be highly appreciated!