shahin
Active Member
Hi there! Hope you all are doing well. I've written some code for the purpose of scraping names and urls from several links found in the left sided bar in a webpage and populate the data in several sheets [also giving each sheet a new name taking a customized portion from url] in a workbook so that things do not get messy and the data can be located separately. I tried to do the whole thing accurately and found it working great. However, the only problem I'm facing is that while scraping the results, the screen is flickering [don't know the actual term to use here]. I tried to turn the display alerts off but I don't think I know the proper usage of it that is because I commented it out in my script. Hope someone will take a look into this. Here is what I did:
Code:
Sub Web_Data()
Const link = "http://www.wiseowl.co.uk"
Dim http As New XMLHTTP60, html As New HTMLDocument, htm As New HTMLDocument
Dim topics As Object, topic As Object, newlinks As String, ws As Worksheet
With http
.Open "GET", "http://www.wiseowl.co.uk/videos/", False
.send
html.body.innerHTML = .responseText
End With
'Application.DisplayAlerts = False
Set topics = html.getElementsByClassName("woMenuList")(0).getElementsByTagName("a")
For x = 1 To topics.Length - 1
newlinks = link & Split(topics(x).href, ":")(1)
With http
.Open "GET", newlinks, False
.send
htm.body.innerHTML = .responseText
End With
With ThisWorkbook
Set ws = .Sheets.Add(After:=.Sheets(.Sheets.Count))
ws.Name = Split(Split(Split(newlinks, "videos/")(1), "/")(1), ".")(0)
End With
Set topic = htm.getElementsByClassName("woVideoListDefaultSeriesTitle")
For Each item In topic
i = i + 1
Cells(i, 1) = item.getElementsByTagName("a")(0).innerText
Cells(i, 2) = link & Split(item.getElementsByTagName("a")(0).href, ":")(1)
Next item
i = 0
Next x
' Application.DisplayAlerts = True
End Sub