VBA code to login a web site and extract data to excel

edneco

New Member
Joined
Jul 1, 2015
Messages
17
Hello everyone... This is my first post here and I think it won´t be the last.....

My knowledge of VBA code is very very limited. The only code I made is from recording some macros.... So you see what point I'am.....

I can get some data from websites trough excel-> Data -> from web and then pick the yellow boxes to import tables (when the sites allow it)..... In my specific case I need to import some data from this site: www.betbrain.com

I don´t know if you know this site. This site is about sports and betting. I want to import the odds from specific football leagues with some specific odds (Bet365)..... In my website preferences, when I login, the Bet365 odds are show in every match. If I don´t login, the odds that appear is the best odds we can bet.

So, I need to login with my username and password to get the odds I want and cpoy them to excel.

I don´t know either if is its possible to do what I want with VBA code. I hope it can......


In this link we have the Premier League (UK) games for the 1st round.

http://www.betbrain.com/football/england/premier-league/


Thank you in advance for any help you can give me on this.......


Cheers, Eduardo


PS -> In the future I´ll need some help to "convert" this to a userform (like an application)......
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello again... I have this code and is almost ready... It populates the username and password fields but don´t do the click function......

Can you help me on this little issue????

Code:
Sub main()

   Dim ie As Object
   
   Set ie = CreateObject("InternetExplorer.Application")
   ie.navigate "www.betbrain.com"

   'wait until the page loads
   Do While ie.ReadyState <> 4
      DoEvents
   Loop
   ie.Visible = True
   
   With ie.document
      'input username="username"
      .GetElementByID("username").Value = "******"
      
       'input name="password"
       .GetElementByID("password").Value = "*******"
       
       'input class="gaia le button" name="signIn" id="signIn" value="Sign in" type="submit"
       .GetElementByID("enter").Click
   End With
   
End Sub


Thank you for any help you can give.......
 
Upvote 0
I check the element and this came up.... Can you guide me on this???

button type="submit" name="LoginButton" class="Button SignInButton" tabindex="4" title="Sign in now!"

Another thing.... Which library(s) do I need to activate in the references tab????
 
Last edited:
Upvote 0
I checked the element and this came up.... Can you guide me on this???

button type="submit" name="LoginButton" class="Button SignInButton" tabindex="4" title="Sign in now!"
Code:
.getElementsByName("LoginButton")(0).Click
Another thing.... Which library(s) do I need to activate in the references tab????
None as coded, because you're using late binding of the IE object. However, coding is easier if you use early binding of IE and HTMLDocument objects, for which you need references to Microsoft Internet Controls and Microsoft HTML Object Library.
 
Upvote 0
Hello again.... After this time, the site I refer above "www.betbrain.com" won´t allow me to copy any of data from their webpages. It´s understandable, because they have a service for that....

Meanwhile I found a new site that in their Terms&Conditions have this statment: "All material on this web site, without limitation, including any text, graphics, logos, photographs, belongs to the operating company (see imprint). You may use any content from this web site just for your personal, non-commercial purposes."

Wettportal.com

Like I said earlier, this is for my personal use and non-commercial. Saying that I need your help to write a code that goes to the page I want, login and copy the table to the sheet. This is the code I have and worked for the betbrain´s page, but for this site don´t work. Need help on this......

Code:
Sub main()

   Dim ie As Object
   
   Set ie = CreateObject("InternetExplorer.Application")
   ie.navigate "http://uk.wettportal.com/Soccer/Belgium//"

   'wait until the page loads
   Do While ie.ReadyState <> 4
      DoEvents
   Loop
   ie.Visible = True
   
   With ie.document

      'Login:
      'input name="username" class="input-loginfield" type="text"
      .GetElementByID("username").Value = "******"
      
       'Password:
       'input name="password" class="input-loginfield" type="password"
       .GetElementByID("password").Value = "********"
       
       '[I]
       .getElementsByTagName("button")(0).Click
                     
   End With
   
End Sub[/I]


So, this code is only to enter the webpage and login (not working now, but it will)...... But then I need to copy the first table (date, time, matches and odds) that contain the next round of that specific soccer league. I will need to copy another 8 soccer league data, but i think if I have one example I can do the rest (hope so)...... Need help on this too....

I already try with "Excel-> Data -> from web" but gives me an error and this method won´t let me login.

Thank you in advance for any help you can give me.....

Best regards, Eduardo

 
Upvote 0
IE blocks the website due to security certificate errors. Sorry, but I don't want to go any further.
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

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