Anda di halaman 1dari 7

**Scrape AUM for Funds**

Sub Macro1()

Dim ie As Object

Set Rng = Range("A3:A6")

Set Row = Range(Rng.Offset(1, 0), Rng.Offset(1, 0).End(xlDown))

Set ie = CreateObject("InternetExplorer.Application")

With ie

'.Visible = True

For Each Row In Rng

.navigate "http://quotes.morningstar.com/fund/fundquote/f?t=" & Range("A" & Row.Row).Value &


"&culture=en_us&platform=RET&viewId1=3144532370&viewId2=2774502275&viewId3=3535322503&t
est=QuoteiFrame"

Do

DoEvents

Loop Until ie.readyState = READYSTATE_COMPLETE

Dim doc As HTMLDocument

Set doc = ie.document

While ie.readyState <> 4

Wend

Application.Wait (Now + TimeValue("0:00:02"))

On Error Resume Next

Range("B" & Row.Row).Value = doc.getElementsByClassName("gr_text1")(3).innerText


Next Row

ie.Quit

End With

End Sub

-----------------------------------------------------------------------------------------------------------------------

**Scrape Firm Name for Funds**

Sub Macro1()

Dim ie As Object

Set Rng = Range("B3:B5")

Set Row = Range(Rng.Offset(1, 0), Rng.Offset(1, 0).End(xlDown))

Set ie = CreateObject("InternetExplorer.Application")

With ie

'.Visible = True

For Each Row In Rng

.navigate "http://financials.morningstar.com/fund/management.html?t=" & Range("B" &


Row.Row).Value & "&region=usa&culture=en-US"

Do

DoEvents

Loop Until ie.readyState = READYSTATE_COMPLETE


Dim doc As HTMLDocument

Set doc = ie.document

While ie.readyState <> 4

Wend

Application.Wait (Now + TimeValue("0:00:02"))

On Error Resume Next

Range("L" & Row.Row).Value = doc.getElementsByTagName("td")(4).innerText

'this enters outputs into column L and grabs the firm name from MS

Next Row

ie.Quit

End With

End Sub

--------------------------------------

**Scrape the URL of the first result in google**

Sub XMLHTTP()

Dim url As String, lastRow As Long

Dim XMLHTTP As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object

Dim start_time As Date

Dim end_time As Date


lastRow = Range("T" & Rows.Count).End(xlUp).Row

'this tells the program when to end; if there is no more text in the next box, it ends

Dim cookie As String

Dim result_cookie As String

start_time = Time

Debug.Print "start_time:" & start_time

For i = 2 To lastRow

url = "https://www.google.co.in/search?q=" & Cells(i, 20) & "&rnd=" &


WorksheetFunction.RandBetween(1, 10000)

'the cells(i,#) is the column number you are referencing

Set XMLHTTP = CreateObject("MSXML2.serverXMLHTTP")

XMLHTTP.Open "GET", url, False

XMLHTTP.setRequestHeader "Content-Type", "text/xml"

XMLHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0)


Gecko/20100101 Firefox/25.0"

XMLHTTP.send

Set html = CreateObject("htmlfile")

html.body.innerHTML = XMLHTTP.responseText

Set objResultDiv = html.getElementById("rso")

Set objH3 = objResultDiv.getElementsByTagName("H3")(0)

Set link = objH3.getElementsByTagName("a")(0)

str_text = Replace(link.innerHTML, "<EM>", "")


str_text = Replace(str_text, "</EM>", "")

Cells(i, 21) = link.href

'the cells(i,#) is the column number you are placing your output in

DoEvents

Next

end_time = Time

Debug.Print "end_time:" & end_time

Debug.Print "done" & "Time taken : " & DateDiff("n", start_time, end_time)

MsgBox "done" & "Time taken : " & DateDiff("n", start_time, end_time)

End Sub

-----------------------------------------------------------------------------------

**Brightscope Data Scrub**

Sub Brightscope_Scrub()

Dim IE As Object

Set rng = Range("U3:U95")

Set Row = Range(rng.Offset(1, 0), rng.Offset(1, 0).End(xlDown))

Set IE = CreateObject("InternetExplorer.Application")

With IE

'.Visible = True

For Each Row In rng

.navigate Range("U" & Row.Row).Value


Do

DoEvents

Loop Until IE.readyState = READYSTATE_COMPLETE

Dim doc As HTMLDocument

Set doc = IE.document

While IE.readyState <> 4

Wend

Application.Wait (Now + TimeValue("0:00:02"))

On Error Resume Next

Range("M" & Row.Row).Value = doc.getElementsByClassName("fp-main-body-text")(3).innerText

'this grabs the firm AUM from BS and enters outputs into stated column

Range("V" & Row.Row).Value = doc.getElementsByClassName("fp-main-body-text")(1).innerText

Range("P" & Row.Row).Value = doc.getElementsByClassName("js-phone-number


number")(0).innerText

Range("W" & Row.Row).Value = doc.getElementsByClassName("fp-type-1")(2).innerText

Next Row

IE.Quit

End With

End Sub

---------------------------------------

**Disable F1**
Application.OnKey "{F1}", ""

---------------------------------------