找回密码
 加入
搜索
查看: 2701|回复: 8

[IE类操作] InetRead 或 winHttp 如何读取 href 类型(这是二次跳转的意思?)的网址、【已解决】

  [复制链接]
发表于 2017-4-26 14:47:37 | 显示全部楼层 |阅读模式
本帖最后由 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 暂时不知道解

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-4-26 14:51:13 | 显示全部楼层
InetRead 两次应该可以的
 楼主| 发表于 2017-4-26 15:18:55 | 显示全部楼层
回复 2# 1361739590


            $a = InetRead('http://www.dataoke.com/qlist/',1)
               
                $b = InetRead('http://www.dataoke.com/qlist/',1)
                MsgBox(0,'',BinaryToString($b,4))

是这样么?还是读不到
发表于 2017-4-26 16:13:27 | 显示全部楼层
$a = InetRead('http://www.dataoke.com/qlist/')
$a = BinaryToString($a,4)
;去a里面把地址找出来,$URL
$b = InetRead($URL,1)
MsgBox(0,'',BinaryToString($b,4))



$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Option(6) = True ;接收重定向地址信息
 楼主| 发表于 2017-4-26 16:30:01 | 显示全部楼层
回复 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))
发表于 2017-4-26 16:30:21 | 显示全部楼层
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[0]
        $sToken_reg = StringRegExp($sCookieReturn,'token=\w+',1)
        If Not @error Then $sToken = $sToken_reg[0]
        $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   
 楼主| 发表于 2017-4-26 16:44:03 | 显示全部楼层
回复 6# zghwelcome


    非常感激帮忙,谢谢啦
发表于 2017-4-26 16:45:05 | 显示全部楼层
回复 5# fenhanxue


    我这边打不开网站,你之前好像说是得到不一样的网址,现在又一样了。
 楼主| 发表于 2017-4-26 16:47:36 | 显示全部楼层
回复 8# 1361739590


    他重定向后还是同一个网址,6楼给了个答案,可以读取到了。还是非常感谢帮忙啦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 19:55 , Processed in 0.084804 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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