Until $a[4] = -1 ;此处出错,为什么?
此段代码是反复post得到最终的url跳转地址,可是为什么$a=-1出错了呢?#include "WinHttp_GetRespond.au3"
#include <Array.au3>
$PMID = "23313498"
Local $html = BinaryToString(InetRead("http://www.ncbi.nlm.nih.gov/pubmed/" & $PMID, 1), 1)
Local $icon = StringRegExp($html, '<a href="([^"]+).+?Icon for', 3)
If Not @error Then
MsgBox(0, 0, "iconurl " & $icon)
Local $a
$a = $icon
;$a = "http://linkinghub.elsevier.com/retrieve/pii/S0022-3913(14)00034-1";出错????????????
Do
$returnHead = $a
_ArrayDisplay($a)
$a = _get($a)
Until $a = -1 ;此处出错,为什么?
$afinal = $returnHead
MsgBox(48, "Final", $afinal)
EndIf
Func _get($sdurl, $sdcookie = "", $sdmoreheader = "");cookie 下载代码
Local $sdOpen, $sdContext
$sdOpen = _WinHttpOpen()
$sdmoreheader = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0"
$sdContext = _WinHTTP_GetRespond($sdOpen, $sdurl, 0 + 2 + 4 + 8, "", "", $sdcookie, $sdmoreheader)
;~ _ArrayDisplay($rContext)
If IsArray($sdContext) Then
Return $sdContext
Else
Return ""
EndIf
;_WinHttpCloseHandle($sdOpen)
EndFunc ;==>_get
回复 1# sex123 #include "WinHttp_GetRespond.au3"
#include <Array.au3>
$PMID = "23313498"
Local $html = BinaryToString(InetRead("http://www.ncbi.nlm.nih.gov/pubmed/" & $PMID, 1), 1)
Local $icon = StringRegExp($html, '<a href="([^"]+).+?Icon for', 3)
If Not @error Then
MsgBox(0, 0, "iconurl " & $icon)
Local $a
$a = $icon
;$a = "http://linkinghub.elsevier.com/retrieve/pii/S0022-3913(14)00034-1";出错????????????
Do
$returnHead = $a
_ArrayDisplay($a)
$a = _get($a)
If Not IsArray($a) Then MsgBox(0, '', "我已经不是数组了,要出错了~")
Until $a = -1 ;此处出错,为什么?
$afinal = $returnHead
MsgBox(48, "Final", $afinal)
EndIf
Func _get($sdurl, $sdcookie = "", $sdmoreheader = "");cookie 下载代码
Local $sdOpen, $sdContext
$sdOpen = _WinHttpOpen()
$sdmoreheader = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0"
$sdContext = _WinHTTP_GetRespond($sdOpen, $sdurl, 0 + 2 + 4 + 8, "", "", $sdcookie, $sdmoreheader)
;~ _ArrayDisplay($rContext)
If IsArray($sdContext) Then
Return $sdContext
Else
Return ""
EndIf
;_WinHttpCloseHandle($sdOpen)
EndFunc ;==>_get 晕,我知道最后一定是post后没有返回数组,所以出错,我是想问怎么办?怎么样反复post,最后得到$a=-1,即没有再跳转,而不是返回不了数组,或者这样问,为什么返回不了数组,怎么避免? 我自已先加一个这个吧,真奇怪,如果post后,没有跳转,不是应该返回-1停止吗,怎么返回不出数组呢?
If Not IsArray($a) Then ExitLoop
@error值为2 本帖最后由 shqf 于 2014-5-13 17:23 编辑
因为最后一次函数返回的是空串,第14句再赋值给$a,$a就变成了非数组变量了,故出错。简单点可这样改:32 句后插入$a = -1, 原33句改成Return $a。不过总感觉数组用得有点儿乱。
页:
[1]