0

I was recently assisted in scraping data from a webpage by the guys at Stackoverflow. It's a great community. I was given a function that pulls data into excel from a cell containing a url. Unfortunately I'm running into some problems because I need a loop function so that Excel does not restart all my functions once I save or refresh the page.

So far I have tried to build this, but am next to useless in VBA. Wondering if anyone can provide a little extra assistance.

Sub POSTPageViews()
Dim InputSheet As Worksheet
Dim i As Long
Dim AllWords As Range
Dim text As String
Dim OutValue As String
Dim driver As SeleniumWrapper.WebDriver
On Error Resume Next

Set driver = New SeleniumWrapper.WebDriver
driver.Start "chrome", "https://re.po.st/"
driver.Open strLocation

Set InputSheet = Active
Set WorkRng = Application.Selection
WordListSheet.Range("E1") = "All Words"
InputSheet.Activate
r = 1

Do While Cells(r, 1) <> ""
  Cells(r, 1).Value = txt
OutValue =        driver.findElementById("sguidtotaltable").findElementByTagName("span").text
 Next i
r = r + 1
driver.stop 'Stops the browser
Loop
End Sub

But naturally it is not working... Anybody see what is wrong? Basically in Column E I have all the URLs and in column K I would like to see the accompanying values.

Thanks

8
  • Maybe I'm just missing it, but I see a Next i with out a For i or any other reference to i for that matter. Commented Aug 17, 2015 at 15:11
  • Also, getting rid of the On Error Resume Next, at least for the moment, will allow the editor to tell you where your code is going wrong and why. Commented Aug 17, 2015 at 15:16
  • mmhm, I've taken that out but still problematic. I'm thinking that I have to define StrLocation? to be Column E? Commented Aug 17, 2015 at 15:19
  • Says "Object Required" after I removed that... Commented Aug 17, 2015 at 15:22
  • If strLocation is where your url is, then I would put it inside your loop. Maybe something like this: driver.Open Cells(r, 5).Value. and you can place driver.stop outside of the loop. The results could be in column F, maybe, like Cells(r, 6) = driver.findElementsById(... Commented Aug 17, 2015 at 15:26

1 Answer 1

1

Does this work (in the spirit of my comments)?

Sub POSTPageViews()
Dim driver As SeleniumWrapper.WebDriver

Set driver = New SeleniumWrapper.WebDriver
driver.Start "chrome", "https://re.po.st/"

With Worksheets("Trial")

r = 2

Do While .Cells(r, 5) <> ""
driver.Open .Cells(r, 5).Value
.Cells(r, 11) =    driver.findElementById("sguidtotaltable").findElementByTagName("span").text
r = r + 1

Loop
driver.stop 'Stops the browser
End Sub
Sign up to request clarification or add additional context in comments.

6 Comments

What is the name of the sheet with the urls? I think we can clean up where you are activating and selecting various sheets and ranges.
Just says Object Required, can't figure out what is going wrong there.
Name of sheet is "Trial" url column is E and output column would be K :)
OK. I edited this code in a way that I think will help and get to the heart of the matter. Try it, please, and tell me what happens.
Just give me a minute, Struggling with wifi (of course :/ ) maybe just a bit longer than a minute
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.