找回密码
 加入
搜索
查看: 3372|回复: 0

[IE类操作] [已解决]怎么用WinHttp来打开这个网址,并返回所生成的网页内容

[复制链接]
发表于 2011-11-25 18:45:46 | 显示全部楼层 |阅读模式
本帖最后由 贺州龙少 于 2011-11-28 12:16 编辑

网址: http://www.xunbo.cc/search.asp?Searchword=杨门

本人一起想用这种方法来操作IE,但到目前为止还没成功过一次。。再此希望有能力的大侠们帮我一把,帮我修改一下代码,让他能正常运作。。。。

我的目的是通过WinHttp来打开一个特定的网址后并获取生成的网页内容
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize
Global $hOpen = _WinHttpOpen()

If @error Then
        MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
        Exit 1
EndIf

; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen, "http://www.xunbo.cc/search.asp?Searchword=杨门") ; <- yours here
If @error Then
        MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
        _WinHttpCloseHandle($hOpen)
        Exit 2
EndIf

; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect)
If @error Then
        MsgBox(48, "Error", "Error creating an HTTP request handle.")
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        Exit 3
EndIf

; Send it
_WinHttpSendRequest($hRequest)
If @error Then
        MsgBox(48, "Error", "Error sending specified request.")
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        Exit 4
EndIf

; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
        MsgBox(48, "Error", "Error waiting for the response from the server.")
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        Exit 5
EndIf

; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
        ; Read
        While 1
                $sChunk = _WinHttpReadData($hRequest)
                If @error Then ExitLoop
                $sData &= $sChunk
        WEnd
        ConsoleWrite($sData & @CRLF) ; print to console
Else
        MsgBox(48, "Error", "Site is experiencing problems.")
EndIf

; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
发表于 2011-11-25 22:54:28 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-11 02:03 , Processed in 0.078823 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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