贺州龙少 发表于 2011-11-25 18:45:46

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

本帖最后由 贺州龙少 于 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)

kk_lee69 发表于 2011-11-25 22:54:28

http://www.autoitx.com/thread-28729-1-1.html
页: [1]
查看完整版本: [已解决]怎么用WinHttp来打开这个网址,并返回所生成的网页内容