Scraping data from a table with AutoHotkey & IE

A cartoon robot with a webcam eye beside a laptop showing a web page, with colorful app icons floating above and a stack of web layouts beside itIn this tutorial I walk through how to “walk the DOM” (DOM= Document Object Model) with IE and AutoHotkey.

I used to grab all the text and then try and use a regular expression to parse the data.  Taking advantage of the DOM is critical to learning how to scrape pages efficiently.   In this case I’m simply relying on built in tags to an HTML table.

Here is the first bit of code I mention to scrape data from a table
found here.

Rip the URL from the Clipboard with AutoHotkey

Someone asked me if I had a tool that would look at the clipboard and return only the URL or Rip the  URL from the Clipboard. (The clipboard has various formats like: Files, Text, Rich Text Format, HTML, Images, etc.).

I used the cool WinClip library which can be grabbed here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/ and, with the help of maestrith, wrote a script which returns the various items on the clipboard in HTML format as an object.

Rip the URL from the Clipboard

 
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance,Force
SetBatchLines,-1
global Com:=ComObjCreate(“HTMLFile”)
;*******************************************************
Browser_Back:: ;Change this hotkey to what you want
CB:=ClipboardAll
Clipboard:=””
while(Clipboard){
Sleep,10
}
Send,^c
while(!Clipboard){
Sleep,10
}
Clip:=Get_Clipboard_Data() ;Call the function and return the HTML data in an object
MsgBox % clip.1.HREF
DebugWindow(Obj2String(Clip),1,1,200,0)
Clipboard:=CB ;restore Clipboard
return

;********************Grab data from Clipboard***********************************
Get_Clipboard_Data(){
wc := new WinClip
wc.iSnap()
Obj:=[]
try:=wc.iGetHTML()
HTML:=SubStr(Try,InStr(Try,”<HTML>”))
Com.Close()
Com.Write(HTML)
All:=Com.GetElementsByTagName(“a”)
Url:=[]
RegExMatch(Try,”OUi)SourceURL:(.*)\R”,Found)
while(aa:=All.Item[A_Index-1]){
URL.Push({Page:Found.1,Text:aa.InnerText,HREF:aa.HREF})
}
return URL
}
;~ https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/
#Include B:\Progs\AutoHotkey_L\AHK Work\WinClip\WinClipAPI.ahk
#Include B:\Progs\AutoHotkey_L\AHK Work\WinClip\WinClip.ahk

Updated iWB2 Learner tool to grab ClassName & Highlight Frames

ClassName & Highlight FramesI use ClassName a lot when web scraping.  So much so I updated the iWB2 Learner tool to extract it from the outerHTML and have it’s own edit field (like Name and ID).

I also changed the ListView that shows Frames to be RED.  I can’t tell you how much time I wasted early-on when dealing with Frames.  Hopefully this will help people realize they need to take a different approach when Frames are present! Continue reading