Essentially it would be a web scraper. I'm either looking for existing free code or a good place to learn how to make one.
Essentially it would be a web scraper. I'm either looking for existing free code or a good place to learn how to make one.
Last edited by 111StepsAhead; 06-14-2012 at 10:23 AM. Reason: Users posted 2 solutions to the problem.
I'm sure there are many different ways, but this may help
![]()
Sub testit() LogIESource "http://www.microsoft.com", "C:\microsoft.txt" End Sub Sub LogIESource(strURL As String, strFilePath As String) Dim objIE As Object Dim FileNumber as long Set objIE = CreateObject("InternetExplorer.Application") ' Get unused file objIE.Navigate strURL Do While objIE.ReadyState <> 4 DoEvents Loop FileNumber = FreeFile ' Create log file Open strFilePath For Output As #FileNumber Print #FileNumber, objIE.Document.DocumentElement.outerhtml ' Close file. Close #FileNumber End Sub
Everyone who confuses correlation and causation ends up dead.
Typically you wouldn't use vba for this, however since you want t ouse VBA, see if this gets you started:
Webscraping can get very complex very quickly and as I said VBA isn't the ideal tool![]()
Sub GetSource() With CreateObject("MSXML2.XMLHTTP") .Open "GET", "http://www.excelforum.com" .send Do: DoEvents: Loop Until .ReadyState = 4 Open ThisWorkbook.Path & "\Output.txt" For Output As #1 Print #1, .responsetext Close #1 End With End Sub
Thanks for the quick responses. Hope you guys didn't have to put too much effort into making that code. I am trying to expand on what I've learned over the last few months here and this seemed like a fun way to do that. Both of your guys code worked great.
I will mark this thread as solved but as an extra question, what programming language would be better for webscraping?
Probably Python![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks