找回密码
 加入
搜索
查看: 10592|回复: 12

[IE类操作] 想用WINHTTP获取指定网页上的字符串

 火.. [复制链接]
发表于 2014-7-19 22:30:38 | 显示全部楼层 |阅读模式
在使用WINHTTP获取指定网页上的字符串,摸索了很久都没找对办法,特来请教

#include <ie.au3>
#include <winhttp.au3>
#include <WinHttpConstants.au3>
Local $userAgent='Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101'
Local $url="http://www.369859.com/renwu.asp"
$aURL_Split = _WinHttpCrackUrl($url)
$hOpen = _WinHttpOpen($userAgent)
$hConnect = _WinHttpConnect($hOpen, $aURL_Split[2])
$hRequest = _WinHttpOpenRequest($hConnect, "GET", $aURL_Split[6])
$txt=_WinHttpReadData($hRequest)
MsgBox(0,"",$txt)
发表于 2014-7-20 08:44:54 | 显示全部楼层
$url="http://www.369859.com/renwu.asp"
$xmlhttp=ObjCreate("msxml2.xmlhttp")
With $xmlhttp
        .open("GET",$url,True)
        .send
        While .readystate<>4
                Sleep(100)
        WEnd
        $str=.responsetext
        MsgBox(0,"",$str)
EndWith
$html=ObjCreate("htmlfile")
With $html
        .open
        .writeln($str)
        MsgBox(0,"",.body.innertext)
EndWith
这样试下
 楼主| 发表于 2014-7-20 13:40:01 | 显示全部楼层
感谢kevinch,学习了
发表于 2014-7-20 13:47:02 | 显示全部楼层
路过顶个
发表于 2014-7-21 09:01:28 | 显示全部楼层
感谢,感谢,学习下
发表于 2014-7-21 12:08:49 | 显示全部楼层
本帖最后由 shqf 于 2014-7-21 12:10 编辑

再简单,但基本的结构不能没有吧。楼主,你请求都没发送出去,怎么能收到消息呢?_WinHttpOpenRequest()语句后加上这二句:
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
发表于 2014-7-21 22:01:03 | 显示全部楼层
发表于 2014-7-21 22:20:05 | 显示全部楼层
2楼kevinch兄的代码令人高山仰止矣!
但不适合新手学习啊.如果套用UDF,他们应该会更容易理解.
#include <ie.au3>
Local $url="http://www.369859.com/renwu.asp"
Local $oIe = _IECreate($url, 0, 0, 1)
If Not IsObj($oIe) Then Exit -1
MsgBox(0,"",_IEBodyReadText($oIe))
 楼主| 发表于 2014-7-24 20:25:52 | 显示全部楼层
本帖最后由 tunnyx 于 2014-7-24 20:27 编辑

感谢各位的帮助,我仔细的看了2楼Kevinch老兄的例子,这个例子是可以直接运行的.但我也遇到的新的困难,这个链接对象我重载总不成功,代码如下
For $i=1 to 500
        $url="http://www.369859.com/renwu.asp"
        $xmlhttp=ObjCreate("msxml2.xmlhttp")
        With $xmlhttp
        .open("GET",$url,True)
        .send
        While .readystate<>4
                Sleep(100)
        WEnd
        $str=.responsetext
        ;MsgBox(0,"",$str)
        EndWith
        $html=ObjCreate("htmlfile")
        With $html
                 .open
                 .writeln($str)
                 $txt=Number(.body.innertext)
                 if $txt>0 Then
                           MsgBox(0,"提醒",.body.innertext,15)
                 EndIf
        EndWith
        $xmlhttp.abort();申明一次重载
        Sleep(600000)
next
发表于 2014-7-24 20:35:12 | 显示全部楼层
你都执行完成了,还abort什么呢,取消掉那句试下
 楼主| 发表于 2014-7-25 05:57:57 | 显示全部楼层
回复 10# kevinch
我是为了一下次循环做准备呀,我给换个位置试试,给放到前面去
发表于 2014-7-25 08:51:03 | 显示全部楼层
来学习一下
 楼主| 发表于 2014-8-8 06:30:33 | 显示全部楼层
最终的结果,我还是换回了winhttp.au3把shqf大神的那两句加上去就正常了,但kevinch大神的处理方法,也十分有参考意义,我在处理别的问题使用了,效果不错.感谢各位的帮助
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-30 07:22 , Processed in 0.082686 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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