Extract data from a webpage and display it on a cell

shirazx3

New Member
Joined
Jul 7, 2022
Messages
23
Office Version
  1. 2021
Platform
  1. Web
Hello,
So I am a total novice with Excel VBA. I am trying to create a scenario where I can extract a particular value (inside an ID tag) from a webpage and display it on a particular cell in my excel worksheet. But it doesn't seem to work. Where am I going wrong? Thanks

Private ch As Selenium.ChromeDriver
Sub Test()

Set ch = New Selenium.ChromeDriver
ch.AddArgument "start-maximized"
ch.Start baseUrl:="https://upxland.me/users"
ch.Get ("/delnia")
Set b = ch.FindElementById("input-87")
Cells(1, 1).Value = b.Text

End Sub
 
Last edited by a moderator:
Thanks for the quick response. I will be using all the tips I've learnt from you and apply it to my project. I'll be posting updates and/or issues that I might face further ahead.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Thanks. I was able to add the button and other users too. But now I am facing a minor issue. The input id (<input id="input-87" readonly="readonly" type="text">) changes at times and I am given an error that "input-87" not found. If I re-run the macro, the error goes away. So I was wondering if there is any static element in the code (inspect window) that I can use as a reference.
 
Upvote 0
If the ID# cannot be predicted you might FindElementsbyClass("v-text-field__slot"); this is a collection of 7 WebElements, and element #1 is the one that contains that Id

But I am confident it's only a timing problem (you get the error, but il you "continue" the macro it will get the result); try extendig that "ch.Wait" to 1500-2000 (millisecs)
 
Upvote 0
Hello once again...I tried the solution above and it works better than previously. So, now Im trying to "SendKeys" my username here in the input box but I cannot find its reference in the source (right picture). The only class here is "form-control" but it is not unique as the password class is same too. So how am I suppose to tag the username text box so as to put the username here.
Thank You.
1657467377425.png
1657467351475.png
 
Upvote 0
It's normal that a collection of "elements"has more than 1 element, so you need to "address" the ones you need...
In this case, for example
VBA Code:
Sub ULOPTLogin()
Dim WPage As Object
Dim myColl As Object
'
'Crea Driver:
'    Set WPage = CreateObject("Selenium.EdgeDriver")
    Set WPage = CreateObject("Selenium.CHRomedriver")
WPage.Start
WPage.Get "https://www.uplandoptimizer.com/"
WPage.Wait 500
WPage.FindElementsByClass("btn")(1).Click
WPage.Wait 1000
'
Set myColl = WPage.FindElementsByClass("form-control")
myColl(1).SendKeys ("UserName")
myColl(2).SendKeys ("HisPassword")
WPage.Wait 500
WPage.FindElementsByClass("btn")(1).Click
'
' ... More instructions
'
End Sub
I'll consider that this discussion is "Closed", so in case you need further help I suggest you open a new thread
 
Upvote 0
I apologize for writing here as I was not sure if I can get hold of you who has been a great mentor to me in this quest of learning something. Thank you for all the help. I will definitely open a new thread once I m facing some issue.
 
Upvote 0

Forum statistics

Threads
1,223,999
Messages
6,175,882
Members
452,679
Latest member
darryl47nopra

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