找回密码
 加入
搜索
查看: 2075|回复: 6

练习写了一个网页源码查看代码

  [复制链接]
发表于 2010-1-14 16:07:02 | 显示全部楼层 |阅读模式
本帖最后由 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-1-15 08:05:26 | 显示全部楼层
好样的......
发表于 2010-1-15 10:16:56 | 显示全部楼层
不错不错!!!
发表于 2010-1-15 20:44:58 | 显示全部楼层
#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

评分

参与人数 2金钱 +30 收起 理由
afan + 20
lpxx + 10 十分感谢

查看全部评分

 楼主| 发表于 2010-1-17 21:23:11 | 显示全部楼层
谢谢老师,学到的不仅仅是代码.
发表于 2010-6-11 18:33:00 | 显示全部楼层
谢谢你,解决了我一个大问题,我也是用得_IEDocReadHTML,一直在找为什么有的网页没法看到诸如评论之类的,试了你的代码之后恍然大悟!!
发表于 2010-6-11 18:37:22 | 显示全部楼层
4#代码写得不错,估计自己都没试过吧!而且,这个代码不能"查看"页面,因为有的字符显示不出来,UTF8的页面.试下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-6 12:32 , Processed in 0.080327 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表