0

This is first time I am trying to extract an excel report from a webpage. Sequence of how my code should work is as under:

  1. Initial URL - brings home page of the website (userid and password saved in browser to autologin) - image1
  2. Click on "Reports"
  3. New page appears (image2)
  4. select from dropdown_module.
  5. Select appropriate from dropdown_reports.
  6. selection in dropdown_reports creates a new dropdown_project.
  7. select from dropdown_project
  8. click on drownload reports (image3)
  9. give path for downloading.

    image41 image12 image23 image34

I am able to reach upto point 3, but not able to proceed ahead. On using inspect element on dropdown_module i get the code (image4)

My using so far is as under:

Set IE = CreateObject("InternetExplorer.Application")
URL = Range("hr_url").Value
IE.Visible = True
IE.navigate URL
Application.StatusBar = " is loading. Please wait..."
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
Application.StatusBar = " Loaded"

Set doc = IE.document
For Each element In doc.all
    If InStr(element.ID, "08191") > 0 Then
        If InStr(element.ID, "AppPress:12") Then
            element.Focus
            element.Click
        End If
    End If
Next element

Application.Wait (5)


Do
DoEvents
Loop Until IE.readyState <> 4

Set doc = IE.document
For Each element In doc.all
    If InStr(element.ID, "0261") > 0 Then
        If InStr(element.ID, "AppPress:6") Then
          MsgBox "element is found"
          element.Options(0).Selected = True
        End If
    End If
Next element

The code isnt able to find the dropdown element and select the 0 index required. Can anyone suggest what is wrong here?

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

I was not aware that scraping was posible with VBA. (Scraping is the way the technique of extracting info from the web with software is called)

You should find this question useful:

Scraping data from website using vba

I am not aware of the posibilities off doing this with VBA that might be limited to internet explorer among other limitations. The little things I've done for that have been with python and a library called beautifulSoup, that is amazing!

https://www.crummy.com/software/BeautifulSoup/bs4/doc/

If you feel curious enough you might want to dive into it, as it is quite simple, and googling what you want to do might take you very far, also if you want to create an excel file with the info you extract.

Hope that helps

rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47