Achilles Posted April 16, 2008 Posted April 16, 2008 (edited) Hey, I have a program that will get the links of a different comics. However, I can't seem to get an embedded IE object to navigate to a picture. Any suggestions? Here's what I'm using (It might take a while to show the GUI since it takes a while to get the links): expandcollapse popup#include<StaticConstants.au3> #include<GuiListBox.au3> #include<IE.au3> #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.6.0 Author: Piano_Man Helped by... Marc - I modified his code for getting Dilbert comics i542 + JamesB - I used their code for the Garfield link PaulIA - For his great AutoItLib (it's built into AutoIt now) Paulie - Helped me with the Explosm comic theguy1000 - Helped me with the xkcd comic and getting the Explosm link Script Function: This script downloads comics from Breakfast Ceareal, Calvin and Hobbes, Dilbert, Doonesbury, Explosm, Garfield, Peanuts and xkcd and shows them in a GUI that has tabs for each cartoon. #ce ---------------------------------------------------------------------------- #noTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> #Include <GDIPlus.au3> #include <INet.au3> #include <Array.au3> #include <String.au3> #include <Misc.au3> _Singleton('DailyComics.au3') Opt('GUIOnEventMode', 1) Opt('GUICloseOnESC', 1) Global Const $NUM_OF_PICS = 10 Global Const $ACHEWOOD = 0, $BREAKFAST_CEREAL = 1, $CALVIN = 2, $DILBERT = 3, $DOONESBURY = 4, $EXPLOSM = 5, $GARFIELD = 6, $GETFUZZY = 7, $PEANUTS = 8, $XKCD = 9 Global Const $NAMES[$NUM_OF_PICS] = ['Achewood', 'Breakfast Cereal', 'Calvin and Hobbes', 'Dilbert', 'Doonesbury', 'Explosm', 'Garfield', 'Get Fuzzy', 'Peanuts', 'xkcd'] Global Const $DOWNLOAD_LOCATION = @TempDir & '\' Global $progress, $checked[1], $progressIndex, $list, $ieObject Global $comics[$NUM_OF_PICS][6] ; 0 = Name ; 1 = Link ; 2 = Full name ; 3 = Width ; 4 = Height ; 5 = Checkbox ID _Setup() While 1 Sleep(500) WEnd Func _Setup() _GDIPlus_Startup() For $i = 0 to $NUM_OF_PICS - 1 $indexToGet = $i $comics[$indexToGet][0] = $NAMES[$indexToGet] $temp = Call('_Get' & StringStripWS($NAMES[$indexToGet], 8) & 'Link') $comics[$indexToGet][1] = $temp[0] Next _GDIPlus_Shutdown() GUICreate('Daily Comics', 750, 395) GuiSetOnEvent($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateLabel('Select a comic', 5, 5, 120, 17) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $list = GUICtrlCreateList('', 5, 30, 220, 365) GUICtrlSetOnEvent(-1, '_Test') GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $oIE = _IECreateEmbedded() $ieObject = GUICtrlCreateObj($oIE, 230, 5, 513, 380) For $i = 0 to $NUM_OF_PICS - 1 _GuiCtrlListBox_AddString($list, $comics[$i][0]) Next GUISetState(@SW_SHOW) EndFunc Func _Test() $sel = _GuiCtrlListBox_GetCurSel($list) $selText = _GuiCtrlLIstBox_GetText($list, $sel) For $i = 0 to $NUM_OF_PICS - 1 If $selText = $comics[$i][0] then $grab = $i ExitLoop EndIf Next Msgbox(0, 'Redirect', $comics[$grab][1]) _IENavigate($ieObject, $comics[$grab][1]) EndFunc Func _Exit() GuiDelete() For $i = 0 to $NUM_OF_PICS - 1 FileDelete($comics[$i][2]) Next Exit EndFunc Func _GetAchewoodLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://achewood.com/') $sourceX = StringSplit($source, @CRLF) $keepX = 0 For $i = 0 to UBound($sourceX) - 1 $pos = StringInStr($sourceX[$i], 'http://m.assetbar.com/achewood/one_strip') If $pos > 0 then $keep = _StringBetween($sourceX[$i], 'http://m.assetbar.com/achewood/one_strip', '" >discuss') If IsArray($keep) then $keepX = $keep[0] Else Return "" EndIf ExitLoop EndIf Next $source = _InetGetSource('http://m.assetbar.com/achewood/one_strip' & $keepX) $sourceX = StringSplit($source, @CRLF) For $i = 0 to UBound($sourceX) - 1 $pos = StringInStr($sourceX[$i], '<img src="http://M.assetbar.com/') If $pos > 0 then $keep = _StringBetween($sourceX[$i], '<img src="http://M.assetbar.com/', '"/></a>') If IsArray($keep) then $ret[1] = $keep[0] Else Return "" EndIf ExitLoop EndIf Next $ret[0] = 'http://M.assetbar.com/' & $ret[1] Return $ret EndFunc Func _GetBreakfastCerealLink() Local $ret[2] = ['', ''] $bYear = @YEAR $bMon = @MON $bDay = @MDAY $size = 0 $count = 0 Do $size = InetGetSize('http://www.smbc-comics.com/comics/' & $bYear & $bMon & $bDay & '.gif') $count += 1 $bDay = Number($bDay) - 1 If Number($bDay) = 0 then $bMon -= 1 If $bMon = 0 then $bYear -= 1 $bMon = 12 EndIf _DateDaysInMonth($bYear, $bMon) EndIf If Number($bDay) < 10 then $bDay = '0' & $bDay Until $size > 0 or $count > 5 $ret[0] = 'http://www.smbc-comics.com/comics/' & $bYear & $bMon & $bDay & '.gif' $ret[1] = $bYear & $bMon & $bDay & '.gif' Return $ret EndFunc Func _GetCalvinAndHobbesLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/ch/' & @YEAR & '/ch' & StringTrimLeft(@YEAR, 2) & @MON & @MDAY & '.gif' $ret[1] = 'ch' & StringTrimLeft(@YEAR, 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetDilbertLink() Local $ret[2] = ['', ''] $pass = InetGet("http://www.dilbert.com/comics/dilbert/archive/index.html", $DOWNLOAD_LOCATION & 'temp.dat') $file = FileOpen($DOWNLOAD_LOCATION & 'temp.dat', 0) $timer = TimerInit() While 1 $line = FileReadLine($file) $position = StringInStr($line,"Today's Dilbert Comic") If $position <> 0 then ExitLoop If TimerDiff($timer) > (1000 * 50) then ExitLoop Wend FileClose($file) $position2 = StringInStr($line,'<IMG SRC="/comics/dilbert/archive/images/') $position2 = $position2 + 41 $datei = StringMid ($line, $position2, ($position-$position2)-16) FileDelete($DOWNLOAD_LOCATION & 'temp.dat') $ret[0] = "http://www.dilbert.com/comics/dilbert/archive/images/" & $datei $ret[1] = $datei Return $ret EndFunc Func _GetDoonesburyLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/db/' & @YEAR & '/db' & StringRight(@YEAR, 2) & @MON & @MDAY & '.gif' $ret[1] = 'db' & StringRight(@YEAR, 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetExplosmLink() Local $ret[2] = ['', ''] $RSS = "http://www.explosm.net/comics/new/" $RSSSource = _INetGetSource($RSS) $Items = StringSplit($RSSSource, @CRLF) $Count = UBound($Items) Dim $Date[$Count], $Link[$Count], $Category[$Count] $index = _ArraySearch($items, '<div id="thebodycontent">') $get = 0 $i = $index While $i < UBound($items) - 1 If StringInStr($items[$i], '<img alt=') then $grab = $i ExitLoop EndIf $i += 1 WEnd $temp = StringSplit($items[$grab], '<img alt="Cyanide and Happiness, a daily webcomic" ', 1) $test = _StringBetween($temp[2], 'src="', '"><') $ret[0] = $test[0] $temp = StringSplit($ret[0], '/') $ret[1] = $temp[$temp[0]] Return $ret EndFunc Func _GetGarfieldLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/ga/' & @YEAR & '/ga' & StringTrimLeft(String(@YEAR), 2) & @MON & @MDAY & '.gif' $ret[1] = 'ga' & StringTrimLeft(String(@YEAR), 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetGetFuzzyLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://www.comics.com/comics/getfuzzy/') $array = StringSplit($source, @CRLF) For $i = 1 to UBound($array) - 1 If StringInStr($array[$i], '<IMG SRC="/comics/getfuzzy/archive/images/getfuzzy') > 0 then $temp = _StringBetween($array[$i], 'images/getfuzzy', '"') If IsArray($temp) then $ret[0] = 'http://www.comics.com/comics/getfuzzy/archive/images/getfuzzy' & $temp[0] $ret[1] = 'getfuzzy' & $temp[0] EndIf Return $ret EndIf Next EndFunc Func _GetPeanutsLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://www.unitedmedia.com/comics/peanuts/') $array = StringSplit($source, @CRLF) For $i = 1 to UBound($array) - 1 If StringInStr($array[$i], '<IMG SRC="/comics/peanuts/archive/images/peanuts') > 0 then $temp = _StringBetween($array[$i], 'peanuts', '"') If IsArray($temp) then $ret[0] = 'http://www.unitedmedia.com/comics/peanuts' & $temp[1] $temp = StringSplit($temp[1], '/') $ret[1] = $temp[$temp[0]] EndIf Return $ret EndIf Next EndFunc Func _GetXkcdLink() Local $ret[2] = ['', ''] $RSS = "http://www.xkcd.com/rss.xml" $RSSSource = _INetGetSource($RSS) $Items = StringRegExp($RSSSource, "(?i)(?s)<item>.*?</item>", 3) $Count = UBound($Items) $Dummy = _StringBetween($Items[0], '<img src="', '"') $ret[0] = $Dummy[0] $temp = StringSplit($ret[0], '/') $ret[1] = $temp[$temp[0]] Return $ret EndFunc Edited April 16, 2008 by Achilles My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
jvanegmond Posted April 16, 2008 Posted April 16, 2008 (edited) Try redirect the IE object instead of the AutoIt GUI Element. expandcollapse popup#include<StaticConstants.au3> #include<GuiListBox.au3> #include<IE.au3> #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.6.0 Author: Piano_Man Helped by... Marc - I modified his code for getting Dilbert comics i542 + JamesB - I used their code for the Garfield link PaulIA - For his great AutoItLib (it's built into AutoIt now) Paulie - Helped me with the Explosm comic theguy1000 - Helped me with the xkcd comic and getting the Explosm link Script Function: This script downloads comics from Breakfast Ceareal, Calvin and Hobbes, Dilbert, Doonesbury, Explosm, Garfield, Peanuts and xkcd and shows them in a GUI that has tabs for each cartoon. #ce ---------------------------------------------------------------------------- #noTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> #Include <GDIPlus.au3> #include <INet.au3> #include <Array.au3> #include <String.au3> #include <Misc.au3> _Singleton('DailyComics.au3') Opt('GUIOnEventMode', 1) Opt('GUICloseOnESC', 1) Global Const $NUM_OF_PICS = 10 Global Const $ACHEWOOD = 0, $BREAKFAST_CEREAL = 1, $CALVIN = 2, $DILBERT = 3, $DOONESBURY = 4, $EXPLOSM = 5, $GARFIELD = 6, $GETFUZZY = 7, $PEANUTS = 8, $XKCD = 9 Global Const $NAMES[$NUM_OF_PICS] = ['Achewood', 'Breakfast Cereal', 'Calvin and Hobbes', 'Dilbert', 'Doonesbury', 'Explosm', 'Garfield', 'Get Fuzzy', 'Peanuts', 'xkcd'] Global Const $DOWNLOAD_LOCATION = @TempDir & '\' Global $progress, $checked[1], $progressIndex, $list, $oIE Global $comics[$NUM_OF_PICS][6] ; 0 = Name ; 1 = Link ; 2 = Full name ; 3 = Width ; 4 = Height ; 5 = Checkbox ID _GDIPlus_Startup() For $i = 0 to $NUM_OF_PICS - 1 $indexToGet = $i $comics[$indexToGet][0] = $NAMES[$indexToGet] $temp = Call('_Get' & StringStripWS($NAMES[$indexToGet], 8) & 'Link') $comics[$indexToGet][1] = $temp[0] Next _GDIPlus_Shutdown() GUICreate('Daily Comics', 750, 395) GuiSetOnEvent($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateLabel('Select a comic', 5, 5, 120, 17) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $list = GUICtrlCreateList('', 5, 30, 220, 365) GUICtrlSetOnEvent(-1, '_Test') GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $oIE = _IECreateEmbedded() $ieObject = GUICtrlCreateObj($oIE, 230, 5, 513, 380) _IENavigate($oIE,"about:blank") For $i = 0 to $NUM_OF_PICS - 1 _GuiCtrlListBox_AddString($list, $comics[$i][0]) Next GUISetState(@SW_SHOW) While 1 Sleep(500) WEnd Func _Test() $sel = _GuiCtrlListBox_GetCurSel($list) $selText = _GuiCtrlLIstBox_GetText($list, $sel) For $i = 0 to $NUM_OF_PICS - 1 If $selText = $comics[$i][0] then $grab = $i ExitLoop EndIf Next Msgbox(0, 'Redirect', $comics[$grab][1]) _IENavigate($oIE, $comics[$grab][1]) EndFunc Func _Exit() GuiDelete() For $i = 0 to $NUM_OF_PICS - 1 FileDelete($comics[$i][2]) Next Exit EndFunc Func _GetAchewoodLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://achewood.com/') $sourceX = StringSplit($source, @CRLF) $keepX = 0 For $i = 0 to UBound($sourceX) - 1 $pos = StringInStr($sourceX[$i], 'http://m.assetbar.com/achewood/one_strip') If $pos > 0 then $keep = _StringBetween($sourceX[$i], 'http://m.assetbar.com/achewood/one_strip', '" >discuss') If IsArray($keep) then $keepX = $keep[0] Else Return "" EndIf ExitLoop EndIf Next $source = _InetGetSource('http://m.assetbar.com/achewood/one_strip' & $keepX) $sourceX = StringSplit($source, @CRLF) For $i = 0 to UBound($sourceX) - 1 $pos = StringInStr($sourceX[$i], '<img src="http://M.assetbar.com/') If $pos > 0 then $keep = _StringBetween($sourceX[$i], '<img src="http://M.assetbar.com/', '"/></a>') If IsArray($keep) then $ret[1] = $keep[0] Else Return "" EndIf ExitLoop EndIf Next $ret[0] = 'http://M.assetbar.com/' & $ret[1] Return $ret EndFunc Func _GetBreakfastCerealLink() Local $ret[2] = ['', ''] $bYear = @YEAR $bMon = @MON $bDay = @MDAY $size = 0 $count = 0 Do $size = InetGetSize('http://www.smbc-comics.com/comics/' & $bYear & $bMon & $bDay & '.gif') $count += 1 $bDay = Number($bDay) - 1 If Number($bDay) = 0 then $bMon -= 1 If $bMon = 0 then $bYear -= 1 $bMon = 12 EndIf _DateDaysInMonth($bYear, $bMon) EndIf If Number($bDay) < 10 then $bDay = '0' & $bDay Until $size > 0 or $count > 5 $ret[0] = 'http://www.smbc-comics.com/comics/' & $bYear & $bMon & $bDay & '.gif' $ret[1] = $bYear & $bMon & $bDay & '.gif' Return $ret EndFunc Func _GetCalvinAndHobbesLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/ch/' & @YEAR & '/ch' & StringTrimLeft(@YEAR, 2) & @MON & @MDAY & '.gif' $ret[1] = 'ch' & StringTrimLeft(@YEAR, 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetDilbertLink() Local $ret[2] = ['', ''] $pass = InetGet("http://www.dilbert.com/comics/dilbert/archive/index.html", $DOWNLOAD_LOCATION & 'temp.dat') $file = FileOpen($DOWNLOAD_LOCATION & 'temp.dat', 0) $timer = TimerInit() While 1 $line = FileReadLine($file) $position = StringInStr($line,"Today's Dilbert Comic") If $position <> 0 then ExitLoop If TimerDiff($timer) > (1000 * 50) then ExitLoop Wend FileClose($file) $position2 = StringInStr($line,'<IMG SRC="/comics/dilbert/archive/images/') $position2 = $position2 + 41 $datei = StringMid ($line, $position2, ($position-$position2)-16) FileDelete($DOWNLOAD_LOCATION & 'temp.dat') $ret[0] = "http://www.dilbert.com/comics/dilbert/archive/images/" & $datei $ret[1] = $datei Return $ret EndFunc Func _GetDoonesburyLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/db/' & @YEAR & '/db' & StringRight(@YEAR, 2) & @MON & @MDAY & '.gif' $ret[1] = 'db' & StringRight(@YEAR, 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetExplosmLink() Local $ret[2] = ['', ''] $RSS = "http://www.explosm.net/comics/new/" $RSSSource = _INetGetSource($RSS) $Items = StringSplit($RSSSource, @CRLF) $Count = UBound($Items) Dim $Date[$Count], $Link[$Count], $Category[$Count] $index = _ArraySearch($items, '<div id="thebodycontent">') $get = 0 $i = $index While $i < UBound($items) - 1 If StringInStr($items[$i], '<img alt=') then $grab = $i ExitLoop EndIf $i += 1 WEnd $temp = StringSplit($items[$grab], '<img alt="Cyanide and Happiness, a daily webcomic" ', 1) $test = _StringBetween($temp[2], 'src="', '"><') $ret[0] = $test[0] $temp = StringSplit($ret[0], '/') $ret[1] = $temp[$temp[0]] Return $ret EndFunc Func _GetGarfieldLink() Local $ret[2] = ['', ''] $ret[0] = 'http://images.ucomics.com/comics/ga/' & @YEAR & '/ga' & StringTrimLeft(String(@YEAR), 2) & @MON & @MDAY & '.gif' $ret[1] = 'ga' & StringTrimLeft(String(@YEAR), 2) & @MON & @MDAY & '.gif' Return $ret EndFunc Func _GetGetFuzzyLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://www.comics.com/comics/getfuzzy/') $array = StringSplit($source, @CRLF) For $i = 1 to UBound($array) - 1 If StringInStr($array[$i], '<IMG SRC="/comics/getfuzzy/archive/images/getfuzzy') > 0 then $temp = _StringBetween($array[$i], 'images/getfuzzy', '"') If IsArray($temp) then $ret[0] = 'http://www.comics.com/comics/getfuzzy/archive/images/getfuzzy' & $temp[0] $ret[1] = 'getfuzzy' & $temp[0] EndIf Return $ret EndIf Next EndFunc Func _GetPeanutsLink() Local $ret[2] = ['', ''] $source = _InetGetSource('http://www.unitedmedia.com/comics/peanuts/') $array = StringSplit($source, @CRLF) For $i = 1 to UBound($array) - 1 If StringInStr($array[$i], '<IMG SRC="/comics/peanuts/archive/images/peanuts') > 0 then $temp = _StringBetween($array[$i], 'peanuts', '"') If IsArray($temp) then $ret[0] = 'http://www.unitedmedia.com/comics/peanuts' & $temp[1] $temp = StringSplit($temp[1], '/') $ret[1] = $temp[$temp[0]] EndIf Return $ret EndIf Next EndFunc Func _GetXkcdLink() Local $ret[2] = ['', ''] $RSS = "http://www.xkcd.com/rss.xml" $RSSSource = _INetGetSource($RSS) $Items = StringRegExp($RSSSource, "(?i)(?s)<item>.*?</item>", 3) $Count = UBound($Items) $Dummy = _StringBetween($Items[0], '<img src="', '"') $ret[0] = $Dummy[0] $temp = StringSplit($ret[0], '/') $ret[1] = $temp[$temp[0]] Return $ret EndFunc Edited April 16, 2008 by Manadar github.com/jvanegmond
Achilles Posted April 16, 2008 Author Posted April 16, 2008 That would make sense... Thanks My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
jvanegmond Posted April 16, 2008 Posted April 16, 2008 That would make sense... Thanks Any time! github.com/jvanegmond
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now