I have this html structure:
<table class="series">
<tr>
<th>1.</th>
<td><div><a href="?id=12">1st part</a></div></td>
</tr>
<tr>
<th>2.</th>
<td><div><a href="?id=13">2nd part</a></div></td>
</tr>
<tr>
<th>3.</th>
<td><div><a href="?id=14">3rd part</a></div></td>
</tr>
<tr>
<th>4.</th>
<td><div><a href="?id=15">4th part</a></div></td>
</tr>
<tr>
<th>5.</th>
<td><b>5th part</b></td>
</tr>
<tr>
<th>6.</th>
<td><div><a href="?id=16">6th part</a></div></td>
</tr>
and what I need is to get url of href always previous part im at. As you can see, in this html im at 5th part, so i need to return "?id=15" as previous part of where im actualy am. The thing is, that current part could be anywhere 1st (in this case, return would be NULL), 2nd, 10th, 50th. Or even all this class could be missing on the page, so return should be also NULL.
my progress is this:
Sub GetPageTitle()
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "www.something.com/do.php?id=5"
Do Until .ReadyState = 4
DoEvents
Loop
'Series
Set my_data = .Document.getElementsByClassName("series")
Dim link
Dim i As Long: i = 2
For Each elem In my_data
Set link = elem.getElementsByTagName("a")(0)
'copy the data to the excel sheet
Debug.Print link.href
Debug.Print link.innerText
i = i + 1
Next
.Quit
End With
End Sub
- this was in order just to debug each href in the element, however the for loop doesnt work, it always debugs just once...
I have of course tried to replace (0) by some automatic increment i, but no change. And also, if I figure the debug, I still at this moment have no idea to get the result of url of previous part whatsoever :(
seriesclasses, as these seem to belong to only a table, this would make sense. You aren't walking through all elements in the table, only, all the elements that haveseriesas there class. Try replacingSet my_data = .Document.getElementsByClassName("series")withSet my_data = .Document.getElementsByClassName("series").getElementsByTagName("a")and walking through that collection instead.ClassNamecollection, try this.set my_data = .Document.getElementsByClassName("series")(0).getElementsByTagName("a"). This will iterate allatags in the first tag with a class ofseries