fuinei
发表于 2012-3-30 16:09:22
回复 30# calora88
163首页才300多K,如果变量可以存放大量的数据难道路是StringInStr查找字符串时对字符串的大小有要求??
calora88
发表于 2012-3-30 18:01:02
#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, "www.163.com") ; <- 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
; MsgBox(0,1,$sData)
MsgBox(0,1,StringInStr($sData, 'http://img1.cache.netease.com/img09/icon/icon.png')) ; ===> 會傳回1700
Else
MsgBox(48, "Error", "Site is experiencing problems.")
EndIf
; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
查找 http://img1.cache.netease.com/img09/icon/icon.png 會傳回 1700
沒有問題
fuinei
发表于 2012-3-31 08:26:13
回复 32# calora88
问题解决,昨天是我大意了,原来winhttp对中文的支持不好,部分字符会变乱码,修改判断条件后问题解决,谢谢!
whitehead
发表于 2012-3-31 22:06:25
不错的方法,学习了
zzbtlc
发表于 2012-4-2 14:27:56
有很多方法的。