您的位置:首页 > 运维架构 > 网站架构

[au3]下载css文件里的图片,保存别人的网站时有用。

2012-01-10 14:56 621 查看
;by onepc 153785587



#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\windows\system32\SHELL32.dll|-123
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <INet.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=F:\myziliao\2011-8-3\au3\downcss\Form1.kxf
$g_szVersion = "qq153785587"
If WinExists($g_szVersion) Then
Exit
EndIf
AutoItWinSetTitle($g_szVersion)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$Form1 = GUICreate("下载css样式文件里的图片   by onepc", 431, 139, 393, 400)
$Group1 = GUICtrlCreateGroup("Select", 8, 8, 417, 83)
$Button1 = GUICtrlCreateButton("Select", 368, 22, 51, 25)
$Input1 = GUICtrlCreateInput("", 64, 24, 297, 21)
$Label1 = GUICtrlCreateLabel("FILE:", 24, 26, 29, 17)
$Label4 = GUICtrlCreateLabel("WEB:", 24, 56, 32, 17)
$Input3 = GUICtrlCreateInput("", 64, 56, 233, 21)
$Input2 = GUICtrlCreateInput("", 304, 56, 113, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("DOWN", 128, 104, 75, 25)
$Button3 = GUICtrlCreateButton("EXIT", 208, 104, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
If GUICtrlRead($Input2)="" Then
MsgBox(0,"提示","输入框不能为空")
Else
GUICtrlSetState($Button2,$GUI_DISABLE)
_ReadHttpOrFile(GUICtrlRead ( $Input1 ))
GUICtrlSetState($Button2,$GUI_ENABLE)
EndIf
Case $Button1
$check = _FileOpenFile()
If $check<>"" Then
GUICtrlSetData ($Input1,$check)
EndIf
GUICtrlSetData($Input2, @YEAR & @MON &  @MDAY &  @HOUR &  @MIN &  @SEC)

Case $Button3
Exit
EndSwitch
WEnd

Func _ReadHttpOrFile($pathtext)
Local $hfile,$partten,$text,$array,$i,$localpath,$localpath1
Local $path = GUICtrlRead($Input3)
Local $lpath = GUICtrlRead($Input2)
;MsgBox (0,"",$path)
;Return
If _checkWeb($pathtext) Then ;yes
$text=_INetGetSource($pathtext)
$text=BinaryToString($text , 4);这样不乱码
Else ;no
$hfile = FileOpen($pathtext)
If $hfile = -1 Then
Return
EndIf
$text=FileRead($hfile)
FileClose($hfile)
EndIf
;MsgBox(0,"",$text)
$partten = '(?i)(?<=url\()([\w/.]*)(?=\))'
$array = StringRegExp($text,$partten,3)
for $i = 0 to UBound($array) - 1
;MsgBox(0,"",@ScriptDir & "\" & $lpath & "\" & StringRegExpReplace($array[$i],"/","\\"));,$array[$i])
$localpath=@ScriptDir & "\" & $lpath & "\" & StringRegExpReplace($array[$i],"/","\\") ;all path
$localpath1=StringRegExpReplace ($localpath,'(?i)(?<=\\)[\w]*\.(gif|png|jpg|bmp|jpeg)',"")
If Not FileExists($localpath1) Then
DirCreate($localpath1)
EndIf
;MsgBox(0,$localpath1,$localpath)
InetGet($path & $array[$i],$localpath,1)
Next
EndFunc ;==>_ReadHttpOrFile

Func _FileOpenFile()
Local $result
Local $var = FileOpenDialog("请选择CSS文件", @ScriptDir & "\", "CSS文件 (*.css)|所有文件 (*.*)", 1  )
If @error Then
$result=""
Else
$result = $var
EndIf
Return $result
EndFunc  ;==>_FileOpenFile

Func _checkWeb($ctext)
Local $partten,$c
$partten = "(?i)http://.*" ;是否是网址
$c= StringRegExp($ctext,$partten,0)
Return $c
EndFunc  ;==>_checkWeb

Func _SplictHttp($intxt,$conid)
Local $partten,$webname,$rer,$i
$partten = '(?i)(?<=/)[\w]*\.css'
If _checkWeb($intxt) Then
GUICtrlSetData($conid,StringRegExpReplace ($intxt,$partten,""))
;GUICtrlSetData($Input2, StringRegExpReplace ($intxt,'[/:.@#%$!~`]',""))
$partten = '(?i)http://([\w.@]*)(?=/)'
$rer = StringRegExp($intxt,$partten,3)
For $i = 0 To UBound($rer) - 1
;MsgBox(0, "RegExp Test with Option 3 - " & $i, $rer[$i])
GUICtrlSetData($Input2,$rer[$i])
Next

EndIf
;MsgBox(0,"",StringRegExpReplace ($intxt,$partten,""))
EndFunc  ;==>_SplictHttp

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
$nID = BitAND($iwParam, 0x0000FFFF)
;$iIDFrom = _WinAPI_LoWord($iwParam)
$iCode = _WinAPI_HiWord($iwParam)
Switch $iCode
Case $EN_KILLFOCUS
Switch $nID
Case $Input1
_SplictHttp(GUICtrlRead($nID),$Input3)
EndSwitch
EndSwitch
EndFunc   ;==>WM_COMMAND
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: