InetRead 或 winHttp 如何读取 href 类型(这是二次跳转的意思?)的网址、【已解决】
本帖最后由 fenhanxue 于 2017-4-26 16:45 编辑$a = InetRead('http://www.dataoke.com/qlist/')
MsgBox(0,'',BinaryToString($a,4))得到的结果为:
<script>window.location.href='http://www.dataoke.com/qlist/?cid=0&px=zh&page=1';</script>
百度了下这个,这个代码的意思应该是页面重新跳转的意思吧?不知道应该如何取的真正的网页文本信息。
用HTTPWatch来看了下,是这样的:
解决办法:winhttp 6楼详解
InetRead 暂时不知道解 InetRead 两次应该可以的{:face (356):} 回复 2# 1361739590
$a = InetRead('http://www.dataoke.com/qlist/',1)
$b = InetRead('http://www.dataoke.com/qlist/',1)
MsgBox(0,'',BinaryToString($b,4))
是这样么?还是读不到 $a = InetRead('http://www.dataoke.com/qlist/')
$a = BinaryToString($a,4)
;去a里面把地址找出来,$URL
$b = InetRead($URL,1)
MsgBox(0,'',BinaryToString($b,4))
{:face (356):}
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Option(6) = True ;接收重定向地址信息 回复 4# 1361739590
不好意思,还是没有读取到,能发一段完整的代码么?
他这个网址,第一次读取和发回的重定向的网址是同一个网址,都是:
http://www.dataoke.com/qlist/
即:Local $url_1 = 'http://www.dataoke.com/qlist/'
$a = InetRead($url_1)
$a = BinaryToString($a,4)
;a的结果为: <script>window.location.href='http://www.dataoke.com/qlist/';</script>
;即从a中找到的重定向的网址:
$URL = 'http://www.dataoke.com/qlist/'
;即 $URL和 原始的网址 $url_1 是同一个网址
$b = InetRead($URL,1)
MsgBox(0,'',BinaryToString($b,4)) Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Local $sCookieReturn = _GetCookieReturn()
If Not @error Then
Local $sCookie = '',$sRamdom = '',$sToken = ''
$sRamdom_reg = StringRegExp($sCookieReturn,'random=\d+',1)
If Not @error Then $sRamdom = $sRamdom_reg
$sToken_reg = StringRegExp($sCookieReturn,'token=\w+',1)
If Not @error Then $sToken = $sToken_reg
$sCookie = $sRamdom & ';' & $sToken
$sHtmlSource = _GetHtmlSource($sCookie)
MsgBox(0,0,$sHtmlSource);//获取网页源码
EndIf
Func _GetHtmlSource($sCookie)
$_geturl = 'http://www.dataoke.com/qlist'
$oHTTP.Open('GET', $_geturl, True)
If @error Then Return SetError(-1)
$oHTTP.Option(4) = 13056 ;忽略错误标志
$oHTTP.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.setRequestHeader("Upgrade-Insecure-Requests", "1")
$oHTTP.setRequestHeader("Referer", $_geturl)
$oHTTP.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
$oHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0")
$oHTTP.setRequestHeader("Connection", "Keep-Alive")
$oHTTP.setRequestHeader("Host", "www.dataoke.com") ;
$oHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
$oHTTP.setRequestHeader("Cookie", $sCookie)
$oHTTP.send()
If @error Then Return SetError(-2)
$oHTTP.WaitForResponse
If @error Then Return SetError(-3)
$sContent = $oHTTP.responsebody
If @error Then Return SetError(-4)
Return BinaryToString($sContent,4)
EndFunc
Func _GetCookieReturn()
$_geturl = 'http://www.dataoke.com/qlist'
$oHTTP.Open('GET', $_geturl, True)
If @error Then Return SetError(-1)
$oHTTP.Option(4) = 13056 ;忽略错误标志
$oHTTP.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.setRequestHeader("Upgrade-Insecure-Requests", "1")
$oHTTP.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
$oHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0")
$oHTTP.setRequestHeader("Connection", "Keep-Alive")
$oHTTP.setRequestHeader("Host", "www.dataoke.com") ;
$oHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
$oHTTP.send()
If @error Then Return SetError(-2)
$oHTTP.WaitForResponse
If @error Then Return SetError(-3)
$sHeader = $oHTTP.getAllresponseheaders
If @error Then Return SetError(-4)
Return $sHeader
EndFunc
回复 6# zghwelcome
非常感激帮忙,谢谢啦 回复 5# fenhanxue
我这边打不开网站,你之前好像说是得到不一样的网址,现在又一样了。 回复 8# 1361739590
他重定向后还是同一个网址,6楼给了个答案,可以读取到了。还是非常感谢帮忙啦
页:
[1]