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

Automate Unicode character encoding for HTML

Unicode character encoding

Our CMS does not support Unicode text thus when we need to search-replace for characters like the and © symbols. This takes a fair amount of time and is easy to miss so I wrote a script in AutoHotKey to automatically handle the Unicode character encoding.

Now I can highlight the word and click a button and  Whamo!  Instant replacement with HTML equivalents!  No more trying to scan text and find illegal characters.

Unicode character encoding

Here is the AutoHotKey code I use.  My code first grabs the highlighted text and copies it to the clipboard, where it manipulates it, then sends it back to the active program I was working in. No more need for Unicode character encoding!

 
gosub Store_Clipboard_Copy_Selected_Text
;http://ahkscript.org/docs/commands/Transform.htm  http://www.w3schools.com/charsets/ref_html_8859.asp
Transform,Clipboard,html,%Clipboard%,3  ;3=numbered expressions used where named expression not available
Clipboard:= RegExReplace(Clipboard, "mUs)&bull;\s(.*).<br>", "    <li>$1</li>") ;convert bullet & br to ul
Clipboard:= RegExReplace(Clipboard, "    <li>(.*)</li>", "  <ul>`r`n    <li>$1</li>`r`n  </ul>") ;convert bullet & br to ul
Clipboard:= RegExReplace(Clipboard, "mUs).<br>", "<br>") ;convert bullet & br to ul

 

Web Scraping with AutoHotKey 106- Web Scraping multiple pages

Web Scraping multiple pages

 Web Scraping multiple pages

Example of how to Web Scraping multiple pages with some simple URL manipulation.  This is where being able to make sure you’ve loaded a page fully, scrape it, then navigate to the next is critical.  Looking for patterns in the URL will help you understand how you’ll be able to navigate to the next page.

A copy of the AutoHotKey syntax writer can be found here.  Remember patience is a virtue and Happy Scraping!

Web Scraping with AutoHotKey 102-Setting values and clicking links

web scraping with AutoHotkey

This is the second video in this series.  Here we practice setting values on a page (kind of reverse of Web Scraping with AutoHotkey however I don’t believe anybody has coined a decent term yet) and clicking links.

Word of warning- some pages want you to fire an “event”.  Sometimes this is tricky.  Given this video is set to an introductory level I only touch a little on the subject.

Web Scraping with AutoHotKey 102-Setting values and clicking links

The syntax for writing the writing the code can be found on my first post here.  There is also an AutoHotKey forum thread you might wish to review here.

Web scraping

 (web harvesting or web data extraction) is a computer software technique of extracting information from websites. Usually, such software programs

Think like a Hacker and Protect Yourself with White Hat Security

You’ll even get training on scraping, you can easily get data off of sites like Yelp and create leads list for your sales team from data available online. Jump into a new, in-demand career. Get the White Hat Security Hacker bundle at SitePoint Shop