练习写了一个网页源码查看代码
本帖最后由 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
好样的...... 不错不错!!! #include <GUIConstantsEx.au3>
#include <Inet.au3>
#include <IE.au3>
$Form1 = GUICreate("Form1", 680, 480, -1, -1)
$Input1 = GUICtrlCreateInput("", 72, 8, 513, 21)
$Input2 = GUICtrlCreateInput("http://", 72, 40, 513, 21)
$Edit1 = GUICtrlCreateEdit("", 8, 72, 660, 400)
$Label1 = GUICtrlCreateLabel("正则", 8, 8, 60, 17)
$Label2 = GUICtrlCreateLabel("网址", 8, 40, 60, 17)
$Button1 = GUICtrlCreateButton("开始", 592, 8, 75, 25)
$Button2 = GUICtrlCreateButton("获取", 592, 40, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$ReadTxt = GUICtrlRead($Edit1)
$ReadExp = GUICtrlRead($Input1)
If Not $ReadExp = "" Then
$array = StringRegExp($ReadTxt, $ReadExp, 3)
$arrays = ""
For $i = 0 To UBound($array) - 1
$arrays &= $array[$i]
Next
GUICtrlSetData($Edit1, $arrays)
EndIf
Case $Button2
$ReadUrl = GUICtrlRead($Input2)
;方法 1
If Not $ReadUrl = "" Then
$string = _INetGetSource($ReadUrl)
GUICtrlSetData($Edit1, $string)
EndIf
;方法 2
;~ If Not $ReadUrl = "" Then
;~ $Ieurl = $ReadUrl
;~ $oHTTP = ObjCreate('microsoft.xmlhttp')
;~ $oHTTP.Open('get', $Ieurl, False)
;~ $oHTTP.Send()
;~ $sReturn = BinaryToString($oHTTP.responseBody)
;~ GUICtrlSetData($Edit1, $sReturn)
;~ EndIf
EndSwitch
WEnd 谢谢老师,学到的不仅仅是代码. 谢谢你,解决了我一个大问题,我也是用得_IEDocReadHTML,一直在找为什么有的网页没法看到诸如评论之类的,试了你的代码之后恍然大悟!! 4#代码写得不错,估计自己都没试过吧!而且,这个代码不能"查看"页面,因为有的字符显示不出来,UTF8的页面.试下
页:
[1]