Scraping Optimization Help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SHD_Shawn
Posts: 3
Joined: 29 May 2018, 16:48

Scraping Optimization Help

19 Jun 2018, 03:26

I added my scraping code below, I would in theory, start on a page with 25 values for me to pull, and appends the way I want it too.

Some pages have less than 25 and gives me error's and blank lines on my .txt. Can smarter minds help me clean this up?

Here is the scraping code for me to use for another area that is working fine.

Code: Select all

    F3::Loop_Scrape()
    Loop_Scrape() {
    If ErrorLevel 
    	return
    else
    prop_1=,prop_2=,prop_3=,prop_4=,prop_5=,prop_6=,prop_7=,prop_8=,prop_9=,prop_10=,prop_11=,prop_12=,prop_13=,prop_14=,prop_15=,prop_16=,prop_17=,prop_18=,prop_19=,prop_20=,prop_21=,prop_22=,prop_23=,prop_24=,prop_25=
    Sleep,150
    	IfWinExist,ahk_class IEFrame
    	{
    		pwb:=WBGet()
    		WinActivate
    	}
    Sleep,350
    	prop_1:=pwb.document.GetElementsByTagName("TD")[1].innerText
    	prop_2:=pwb.document.GetElementsByTagName("TD")[12].innerText
    	prop_3:=pwb.document.GetElementsByTagName("TD")[23].innerText
    	prop_4:=pwb.document.GetElementsByTagName("TD")[34].innerText
    	prop_5:=pwb.document.GetElementsByTagName("TD")[45].innerText
    	prop_6:=pwb.document.GetElementsByTagName("TD")[56].innerText
    	prop_7:=pwb.document.GetElementsByTagName("TD")[67].innerText
    	prop_8:=pwb.document.GetElementsByTagName("TD")[78].innerText
    	prop_9:=pwb.document.GetElementsByTagName("TD")[89].innerText
    	prop_10:=pwb.document.GetElementsByTagName("TD")[100].innerText
    	prop_11:=pwb.document.GetElementsByTagName("TD")[111].innerText
    	prop_12:=pwb.document.GetElementsByTagName("TD")[122].innerText
    	prop_13:=pwb.document.GetElementsByTagName("TD")[133].innerText
    	prop_14:=pwb.document.GetElementsByTagName("TD")[144].innerText
    	prop_15:=pwb.document.GetElementsByTagName("TD")[155].innerText
    	prop_16:=pwb.document.GetElementsByTagName("TD")[166].innerText
    	prop_17:=pwb.document.GetElementsByTagName("TD")[177].innerText
    	prop_18:=pwb.document.GetElementsByTagName("TD")[188].innerText
    	prop_19:=pwb.document.GetElementsByTagName("TD")[199].innerText
    	prop_20:=pwb.document.GetElementsByTagName("TD")[210].innerText
    	prop_21:=pwb.document.GetElementsByTagName("TD")[221].innerText
    	prop_22:=pwb.document.GetElementsByTagName("TD")[232].innerText
    	prop_23:=pwb.document.GetElementsByTagName("TD")[243].innerText
    	prop_24:=pwb.document.GetElementsByTagName("TD")[254].innerText
    	prop_25:=pwb.document.GetElementsByTagName("TD")[265].innerText
    Sleep,350
    FileAppend,%prop_1%`n%prop_2%`n%prop_3%`n%prop_4%`n%prop_5%`n%prop_6%`n%prop_7%`n%prop_8%`n%prop_9%`n%prop_10%`n%prop_11%`n%prop_12%`n%prop_13%`n%prop_14%`n%prop_15%`n%prop_16%`n%prop_17%`n%prop_18%`n%prop_19%`n%prop_20%`n%prop_21%`n%prop_22%`n%prop_23%`n%prop_24%`n%prop_25%`n,Docs/MyFile2.txt
    return
    }
Last edited by SHD_Shawn on 19 Jun 2018, 03:41, edited 1 time in total.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Scraping Optimization Help

19 Jun 2018, 03:33

These links redirect to a main page and I cannot see the data you are talking about
SHD_Shawn
Posts: 3
Joined: 29 May 2018, 16:48

Re: Scraping Optimization Help

19 Jun 2018, 03:39

The values themselves don't really matter, I was linking that to help illustrate my point, the crux of it is that sometimes there are less than 25 prop value's on a given page.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Scraping Optimization Help

19 Jun 2018, 13:12

SHD_Shawn wrote:I added my scraping code below, I would in theory, start on a page with 25 values for me to pull, and appends the way I want it too.

Some pages have less than 25 and gives me error's and blank lines on my .txt. Can smarter minds help me clean this up?
Untested but should give the basic concept of using loops to reduce repeative code.

Code: Select all

    F3::Loop_Scrape()
    
	Loop_Scrape() {
		IfWinExist,ahk_class IEFrame
		{
			pwb:=WBGet()
			WinActivate
		}
		Sleep,350
		X := 1, S := ""
		while (X<=265)
		{
			if (T := pwb.document.GetElementsByTagName("TD")[X].innerText)
				S .= T "`n"
			X += 11
		}
		Sleep,350
		FileAppend,%S%,Docs/MyFile2.txt
		return
    }
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 214 guests