DanW
DanW

Reputation: 303

Logging in and out of website with visual basic

As part of a VB project, I need to be able to log in and out of bing.com by automating internet explorer. I've found the href that I need in the page source, but I'm having trouble drilling down through the elements to pull it into the vb program. I pasted the sourcecode down to the line of interest at the end of this post. Below is the line I need. It is also highlighted in the sourcecode.

<a href="https://ssl.bing.com/fd/auth/signin? action=interactive&amp;provider=windows_live_id&amp;return_url=http%3a%2f%2fwww.bing.com%2f &amp;src=EXPLICIT&amp;sig=72D4985D43BA4056A014D3E55105E5EA" class="b_toggle"     h="ID=SERP.5064,5013.1"><div class="idp_wlid"></div><span class="id_name">Microsoft account</span><div class="b_cm" style="display:none"></div><span class="id_link_text">Connect</span></a>

I've tried the following with no success:

IE = CreateObject("InternetExplorer.Application")
IE.Navigate ("bing.com")

' Wait while IE loading...
Do While IE.Busy
    Threading.Thread.Sleep(1000)
Loop

str=IE.getelementbyid("hp_sw_hdr").getelementsbytagname("li")(0).innertext

enter image description here

Upvotes: 2

Views: 625

Answers (1)

DanW
DanW

Reputation: 303

Found a workaround. To log out I cleared the IE cookies using Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2" and exited the browser. Then, to log in, I went to login.live.com and entered username and password. Then I navigated to bing.com. This avoided the need to dig through all the html to get the login link

Upvotes: 1

Related Questions