XMLHTTPRequest and VBA

Jishnu Surendran

New Member
Joined
Jul 29, 2013
Messages
32
I would want to login to a website using xmlhttprequest. My code is

Dim xmlreq As New MSXML2.XMLHTTP60
Dim htmldoc As New MSHTML.HTMLDocument
Dim htmlmsg As MSHTML.IHTMLElement
xmlreq.Open "GET", "https://yyy.com/main.php?pid=406&action=zz", False, "user", "password"
xmlreq.send
htmldoc.body.innerHTML = xmlreq.responseText
Set htmlmsg = htmldoc.getElementById("search-btn")
Debug.Print htmlmsg.innerText

This code is not getting me past the login page, stuck in there. Apart from the 'username' and 'password', I would need to provide a third field which is a dropdown selection before submitting.


I do not know how to pass this field to my code. Below is a screenshot of the login form.

1582751929515.png
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi there,
logging in there seems a bit harder, as they use a POST command to do that... If you open the start page without logging in, click Inspect and the network tab. Next, fill "a" for login ID and b for password, press the button and the network will show a couple of files that are loaded/run. the login.php is a POST command with the "Form Data" as the data that is sent. So you could go in the redirection your code is going, but then you'd have to construct a valid POST command to log in (a bit more complicated vs your GET command.
Otherwise, try this code: VBA-Excel: Automate Internet Explorer (IE) using Microsoft Excel – Login into Gmail. – Excel-Macro -> it basically opens an Internet Explorer and tries to fill boxes and click buttons. Good luck and don't hesitate to ask another question if you get stuck again.

1583141143383.png
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top