您的位置:程序门 -> vb -> 网络编程



研究winsock的人进,用winsock模拟拿取网页数据


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


研究winsock的人进,用winsock模拟拿取网页数据
发表于:2007-01-31 20:40:15 楼主
dim   mycommand   as   string
dim   getpage   as   string

private   sub   command1_click()
with   winsock1
.remotehost   =   "www.baidu.com "
.remoteport   =   80
.connect
end   with
end   sub

private   sub   winsock1_connect()
dim   mycommand   as   string
on   error   resume   next
mycommand   =   text2.text
'给远程计算机发送数据
winsock1.senddata   mycommand
end   sub

private   sub   winsock1_dataarrival(byval   bytestotal   as   long)
winsock1.getdata   webdata,   text
debug.print   webdata
if   instr(data,   "content-type: ")   then
        dim   pos%,   length%,   head$
        pos   =   instr(data,   vbcrlf   &   vbcrlf)
        length   =   len(data)
        head   =   left(data,   pos   -   1)
        data   =   right(data,   length   -   pos   -   3)
        getpage   =   data
end   if
text1   =   getpage
end   sub

text2里面的内容是:
get   /   http/1.1
accept:   */*
accept-language:   zh-cn
ua-cpu:   x86
accept-encoding:   gzip,   deflate
user-agent:   mozilla/4.0   (compatible;   msie   7.0;   windows   nt   5.1;   maxthon)
host:   www.baidu.com
connection:   keep-alive
cookie:   baiduid=e7abb1bd7d6ece10d367e035be6660dd


为什么这样拿到的数据是乱码呢?
发表于:2007-01-31 20:42:191楼 得分:0
帮顶有分
发表于:2007-01-31 21:31:572楼 得分:0
看看这个可能对你有帮助
http://community.csdn.net/expert/topic/5313/5313523.xml?temp=4.580325e-02
发表于:2007-01-31 22:16:013楼 得分:0
akunkeji(阿坤)   ,那网页我去看了,里面说的是utf-8编码问题,但baidu可是gb2312编码
发表于:2007-02-01 00:13:514楼 得分:0
accept-encoding:   gzip,   deflate
///////////
可能是这个问题,没设置好格式,参考下面的get格式:

get   /   http/1.1
host:   www.baidu.com
user-agent:   mozilla/5.0   (windows;   u;   windows   nt   5.1;   en-us;   rv:1.7.6)
connection:   keep-alive
发表于:2007-02-01 01:10:425楼 得分:0
baoaya(点头)   ,请加我qq,我还有一问题想问
发表于:2007-02-01 13:23:126楼 得分:0
我的qq是:20284516
发表于:2007-02-01 13:27:517楼 得分:0
哎,还是自己解决了
发表于:2007-02-01 17:44:548楼 得分:0
private   sub   command1_click()
with   winsock1
.remotehost   =   "www.baidu.com "
.remoteport   =   80
.connect
end   with
end   sub

发表于:2007-02-01 17:47:069楼 得分:0
按错建。
只想以下的代码可以连接吗?

.remotehost   =   "www.baidu.com "   '换做ip可不可以?

private   sub   command1_click()
with   winsock1
.remotehost   =   "www.baidu.com "
.remoteport   =   80
.connect
end   with
end   sub
发表于:2007-02-04 00:10:5010楼 得分:0
学习,我也想知道vb怎样和web服务器页面进行通讯
发表于:2007-02-04 10:49:2511楼 得分:0
先mark   慢慢研究


快速检索

最新资讯
热门点击