Forum

Scrape Address from...
 
Notifications
Clear all

Scrape Address from Web Page

5 Posts
2 Users
0 Reactions
173 Views
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
Topic starter
 

Hi Phil,

 

Im an absolut beginner (so far just a bit of vba) and are currently just trying to get a grip on your code. Thanks for that!

Your Code:

                    HTML.body.innerHTML = http.responseText
                           
                    Set links = HTML.getElementsByTagName("a")
                    For Each link In links
                    Cells(Cells(Rows.Count, "F").End(xlUp).row + 1, "F").Value = link.href
                    Next

Im wondering, you are looking for "<a" and you are extracting everything in between. I see how that works. In my case, I would like to extract the address, but I can’t detect what to search for in this case. Because the <address> sits between two closed brakets...

The code I get from the website:

    

<address>

           <b><a class="details-link" href="/0ewtewgs1"> Name of company</a></b><br>

           Main Street<br>

           80809 München<br>

               Fon: 3434325325235<br>

           <a href="mailto:[email protected]">[email protected]</a><br>

       </address>

 

What do I have to code to get:

 

Name of company

Main Street

80809 München

Fon: 3434325325235

[email protected]

 

Thanks a lot for your help and greetings from Germany!

 
Posted : 18/03/2020 4:44 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
Topic starter
 

Hi Reshera,

What website are you trying to get this from?

Phil

 
Posted : 18/03/2020 6:46 pm
(@reshera)
Posts: 2
New Member
 

Hi Phil,

 

thanks for your promt reply. Unfortunately I cant name the Website here. It shows the addresses where to find their stores. Can You help me nevertheless?

 
Posted : 19/03/2020 2:55 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
Topic starter
 

Hi Reshera,

I can only give you generic code without seeing the actual site.  This worked with a dummy HTML file I created.

Option Explicit

' Written by Philip Treacy
'  https://www.myonlinetraininghub.com/web-scraping-filling-forms 

Sub Scrape()

    Dim Driver As New Selenium.ChromeDriver
    Dim URL As String
    Dim addresses As Object
    Dim address As Variant
    
   URL = "website-address"
   
    
    Set Driver = CreateObject("Selenium.ChromeDriver")
    
    Driver.Get URL
    
    Set addresses = Driver.FindElementsByTag("address").Text
        
        
    For Each address In addresses
        
        Debug.Print address
            
    Next
            
    Driver.Quit
        
End Sub

 

You'll need to use the SeleniumBasic driver to get this to work, I couldn't get native VBA to work.  Not sure it understood the <address>tags.

The attached workbook is adapted from this post

https://www.myonlinetraininghub.com/web-scraping-filling-forms

Cheers

Phil

 
Posted : 20/03/2020 12:43 am
(@reshera)
Posts: 2
New Member
 

Hi Phil,

 

thank You very much. Ill try if I can figure that out.

 

Meanwhile, I just used another tag "div", which extracted a huge sequence of text which I have to seperate into the sections im looking for later on. Pretty sure, ist not a nice way to do it cause it creates an insane amount of data, but at least i can get what im lookin for.

 
Posted : 23/03/2020 11:07 am
Share: