Active Member
March 18, 2020
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:info@gmail.de">info@gmail.de</a><br>
</address>
What do I have to code to get:
Name of company
Main Street
80809 München
Fon: 3434325325235
Thanks a lot for your help and greetings from Germany!
October 5, 2010
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.myonlinetraininghu.....ling-forms
Cheers
Phil
Active Member
March 18, 2020
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.
1 Guest(s)