本帖最后由 lpxx 于 2010-1-17 21:29 编辑
练习写了一个网页源码查看代码,为什么有些类似index.aspx后缀无法获取?
其次,判断输入的网址这块怎么写?
有些网页不存在会自动跳到114,这么怎么判断?
也许代码很幼稚,厚着脸皮问了。#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ie.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("获取网页源码", 518, 447, 192, 124)
GUISetBkColor(0xA6CAF0)
$Input1 = GUICtrlCreateInput("", 80, 48, 233, 21)
$Edit1 = GUICtrlCreateEdit("", 8, 80, 497, 305)
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("输入网址:", 8, 48, 64, 17)
$Button1 = GUICtrlCreateButton("获取源码", 24, 408, 57, 25)
$Button2 = GUICtrlCreateButton("清空", 94, 409, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Http()
Case $Button2
GUICtrlSetData($Edit1, '')
EndSwitch
WEnd
Func Http()
$d=GUICtrlRead($Input1)
If $d <> '' Then
$oHTTP = _IECreate($d, 0, 0, 1, 0)
If @extended Then
MsgBox(0, "糟糕", "网页不存在或者拼写错误")
Else
MsgBox(0, "恭喜", "网址存在")
EndIf
$HTMLSource = _IEDocReadHTML($oHTTP)
GUICtrlSetData($Edit1,GUICtrlRead($Edit1)&$HTMLSource)
Else
MsgBox(4096, "注意","请输入网址","2")
EndIf
GUICtrlSetData($Edit1," ",True)
EndFunc
|